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
Dolfandave Uyemura
Ranch Hand
Joined: Jun 11, 2002
Posts: 31
posted
0
Also, I forgot to mention my Autoexec.bat file looks like this(below) and I did restart my computer after I made the changes to this file and THEN compiled and tried to execute CreateTable.java: SET JAVA_HOME=C:\j2sdk1.4.1_01 SET CATALINA_HOME=C:\jakarta-tomcat-4.1.24 SET CLASSPATH=C:\jakarta-tomcat-4.1.24\common\lib\servlet.jar;C:\%CLASSPATH%;C:\jakarta-tomcat-4.1.24\common\lib\mysql-connector-java-3.0.9-stable\mysql-connector-java-3.0.9-stable-bin.jar;. SET PATH=%path%;C:\WINDOWS;C:\;C:\j2sdk1.4.1_01\bin SET BLASTER=A220 I7 D1 H7 P330 T6 SET SBPCI=C:\SBPCI Thanks again. Dolfandave
Thanks! I can't believe it was that easy. I guess I was getting tired late last night and wasn't thinking clearly. If you have time, how does the rest of the setup look? Thanks again. ddave
If you have time, how does the rest of the setup look?
Close that Statement object in the same way you close the Connection (in the finally block) and you are golden. If you were doing queries that returned ResultSets, you'd want to do the same with them, too.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: ClassNotFoundException Error Giving Me Grief