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!