• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

could not locate driver

 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic