Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
Don't mess with me you fool! I'm cooking with gas! Here, read this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic