Hi there,

I'm in the process of creating a utility program that builds a table in a database and inserts the initial data.

I'm getting an error stating:
java.sql.SQLException: No suitable Driver found for jdbc.odbc.ContactKeeperDB

My Code:

import java.sql.*;
import java.io.*;

public class MakeDB {

	public static void main(String args[]) throws Exception {

	//DataBase Properties
	String JDBCdriver = "sun.jdbc.odbc.JdbcOdbcDriver";
	String DBname = "ContactDataBase";
	String DBUrl = "jdbc.odbc.ContactKeeperDB";

	//Load DataBase Driver
	Class.forName(JDBCdriver);

	//Connect to DataBase
	Connection con = DriverManager.getConnection(DBUrl);

	//Create Statement Object
	Statement stmt = con.createStatement();

	///////////////////////////Create Database Table///////////////////////////

	try{
		System.out.println("Creating Contacts Table with Primary Key Index...");

		stmt.executeUpdate("CREATE TABLE Contacts ("
							+"Name TEXT(20) NOT NULL"
							+"CONSTRAINT PK_Contacts PRIMARY KEY, "
							+"Surname TEXT(20) NOT NULL, "
							+"Mobile TEXT(20) NOT NULL, "
							+"Home TEXT(20) NOT NULL, "
							+"Work TEXT(20) NOT NULL, "
							+"Email TEXT(20) NOT NULL"
							+")");
	}
	catch (Exception e)
	{
		System.out.println("Exception Creating Contacts Table"+ e.getMessage());
	}

	//Create one initial Contact
	String name = "Dean";
	String surname = "Grobler";
	String mobile = "0794400541";
	String home = "NA";
	String work = "NA";
	String email = "dean3446@gmail.com";

	PreparedStatement pStmt = con.prepareStatement("INSERT INTO Contacts VALUES (?,?,?,?,?,?)");

	try
	{
		pStmt.setString(1, name);
		pStmt.setString(2, surname);
		pStmt.setString(3, mobile);
		pStmt.setString(4, home);
		pStmt.setString(5, work);
		pStmt.setString(6, email);
		pStmt.executeUpdate();
	}
	catch(Exception e)
	{
		System.out.println("Exception creating initial user" + e.getMessage());
	}

	pStmt.close();

	}

}

I'm quite new to this so it's probably a very stupid/common mistake. Any suggestions would be great!

Thanks alot!

Note this is a runtime error, the program compiles fine

Because you have mangled your url. See the tutorials.

I've got the MS Access Database file called "ContactKeeperDB" in the same directory as the utility programs .class file. So in my URL I can literaly just say "ContactKeeperDB" ?

nevermind, fixed it. Wasn't really "mangled" I'd say, I just used "." instead of ":".
Thanks Masi

Yes, I could have said that, but by finding that little thing yourself, you now know it well enough that you will either never again make that mistake, or will know to check for it if you do.

make a new path in environmental variale like this : C:\Program Files (x86)\Java\jre8\bin;C:\Program Files (x86)\Java\jre8\lib
your program will work definatly :)

This answwer is a bit late for a 3 year old question

and wrong too

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.