aspose file tools*
The moose likes JDBC and the fly likes could not locate driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "could not locate driver" Watch "could not locate driver" New topic
Author

could not locate driver

Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
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


Rob Petterson
SCJP
Michael Zalewski
Ranch Hand

Joined: Apr 23, 2002
Posts: 168
I just posted the answer to this on another thread. (Well... not quite the same question. But the answer is the same).
Doesn't look like you are registering the driver. Only loading the class. Try

[ December 02, 2002: Message edited by: Michael Zalewski ]
Rob Petterson
Ranch Hand

Joined: Jan 23, 2002
Posts: 149
Thanks Michael,
I'll try this out tonight on my home PC and let you know how I get on.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: could not locate driver