Hi,
I am trying to create my first database driven website. So far, I have gotten to the point where I have successfully downloaded and installed MySQL. I know this because I created a database and tables with it. And successfully did the same with Jakarta-Tomcat and
Java. I went to
Tomcat's examples at
http://localhost:8080/examples/jsp/index.html and successfully executed them so I know it all works on my standalone PC at home.
The part I am stuck on is the actual name of the
JDBC driver. I am using Wrox Presses Beginning
JSP Web Development text. On Chapter 15 it teaches database connectivity. It mentions to go to the MySQL site and download a driver. I did though I am not positive it is the best one for my situation. I run W98 at home. I selected mysql-connector-java-3.0.9-stable-bin.jar and downloaded it to this path on my PC: C:\jakarta-tomcat-4.1.24\common\lib\mysql-connector-java-3.0.9-stable. I saved the CreateTable.java file that is in the text to: C:\jakarta-tomcat-4.1.24\webapps\begjsp-ch15\web-inf\classes
There are folders called "classes" and "lib" in the web-inf folder per the text.
My question is what do I name the driver? I keep getting the "ClassNotFoundException: Could not locate driver" error when I execute CreateTable.java. The book uses the name "org.gjt.mm.mysql.Driver" but that is not the one I downloaded. In fact I did not see that driver on mysql.com. I used "org.gjt.mysql-connector-java-3.0.9.Driver" and various combinations of this name to no avail.
I used my user_id and password on line 10 but did not list it here for security. It is line 8 in the "Class.forName" where I believe my problem is. The next part will be running this application on my shared server. If anyone has any tips on that as well please holler. Please help and thanks.
My CreateTable.java looks like this:
==========================================
import java.sql.*;
public class CreateTable {
public static void main(
String args[]) {
Connection con = null;
try {
Class.forName("org.gjt.mysql-connector-java-3.0.9.Driver").newInstance();
System.out.println("JDBC driver loaded");
con = DriverManager.getConnection("jdbc:mysql://localhost/wrox ?user=myuserid&password=my_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.");
}
}
}
}
==============================
Thanks again.
Dolfandave