Chapter 16 - Driver Not Found - Please Help
Hi everyone,
I was wondering if I could get some help. Everything was going fine in chapter 15 when I used java programs to connect to the database and execute updates and queries. Now, when I try to encapsulate the connectivity into a bean and use the jsp page "booklist.jsp" to connect, an exeception is thrown to the error page which says that my driver is not found. Here is the code segment from Books.java which does the connecting:
package com.wrox.databases;
import java.sql.*;
import java.util.*;
public class Books {
String error = "";
Connection con = null;
public Books() { }
public void connect() throws ClassNotFoundException,
SQLException,
Exception {
try {
Class.forName("com.mysql.jdbc.Driver").newInst ance();
con = DriverManager.getConnection("jdbc:mysql://localhost/wrox ?user=wil324");
System.out.println("Database connection established");
} catch (ClassNotFoundException cnfe) {
error = "ClassNotFoundException: Could not locate DB driver.";
throw new ClassNotFoundException(error);
} catch (SQLException cnfe) {
error = "SQLException: Could not connect to database.";
throw new SQLException(error);
} catch (Exception e) {
error = "Exception: An unknown error occurred while connecting " +
"to database.";
throw new Exception(error);
}
}
.
.
.
The part where the username and password are needed worked the way it is in the previous programs that I did in Chapter 15. Since a username and password was established for winmysqladmin, I assume that specifying the username and password is not important if I'm running winmysqladmin. Please note that my jsp page that is using the "connect" class in Books.java is actually communicating with it (this is evident because of the error that I get). However, in the environment tab of "winmysqladmin" the text area under myODBC says "Not Found Driver 3.51 not found." Also, I don't think there is a problem with the way my classpath is set because I have connected to the database in previous java programs, but they were more direct (not from a jsp page to a java program). Please help me if you can.
|