I'm trying to run the code example in Beginnig
JSP Web Development,
chapter 15,page 463, CreateTable class.
It compiles, but I get the message 'could not locate driver' when trying
to run the prog.
The program file is here:
C:\jakarta-tomcat-4.1.12-LE-jdk14\jakarta-tomcat-4.1.12-LE-jdk14
\webapps\begjsp-ch15\WEB-INF\classes
here's the code:
import java.sql.*;
public class CreateTable {
public static void main(
String args[]) {
Connection con = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
System.out.println("JDBC driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost/wrox ?
user=username&password=user_password");
System.out.println("Database connection established");
Statement stmt = con.createStatement();
String upd = "CREATE TABLE Author ("
+ "Author_ID INTEGER NOT NULL PRIMARY KEY, "
+ "Author_Name CHAR(50));";
stmt.executeUpdate(upd);
System.out.println("Table - Author created");
upd = "CREATE TABLE Category "
+ "(Category_ID INTEGER NOT NULL PRIMARY KEY"
+ ",Category_Description CHAR(50));";
stmt.executeUpdate(upd);
System.out.println("Table - Category created");
upd = "CREATE TABLE Contribution ("
+ "Contribution_ID INTEGER NOT NULL PRIMARY KEY,"
+ "Title_ID INTEGER,Author_ID INTEGER);";
stmt.executeUpdate(upd);
System.out.println("Table - Contribution created");
} catch (ClassNotFoundException cnfe) {
System.out.println("ClassNotFoundException: Could not locate
driver");
} catch (SQLException cnfe) {
System.out.println("SQLException: "+cnfe);
} catch (Exception e) {
System.out.println("An unknown error occurred while connecting to
the database");
} finally {
try {
if ( con != null )
con.close();
} catch(SQLException sqle) {
System.out.println("Unable to close database connection.");
}
}
}
}
My class path is:
C:\jakarta-tomcat-4.1.12-LE-jdk14\jakarta-tomcat-4.1.12-LE-jdk14
\common\lib\servlet.jar;C:\jakarta-tomcat-4.1.12-LE-jdk14\jakarta-tomcat-
4.1.12-LE-jdk14\common\lib\mysql-connector-java-2.0.14;
The driver I've downloaded is located here:
C:\jakarta-tomcat-4.1.12-LE-jdk14\jakarta-tomcat-4.1.12-LE-jdk14
\common\lib\mysql-connector-java-2.0.14
Where am I going wrong?
p.s.
I havn't changed the default user name or password in MySQL - does that
make any difference?
Thanks
Rob