Hi,
I am trying to connect mysql database in jsp file. Mysql itself works well. but when I
use jsp file, I got ClassNotFoundException caused by could not load JDBC/mysql Driver.
I have installed mm.mysql.Driver. If connect by java code only, it works well. I do
not know why the same kind of code does not work for jsp file, does my tomcat has any
problem?
I am in Linux, tomcat is working with Apache.
This is the jsp code I am using:
...
<%@page language="java"
import="java.sql.*"%>
<%
Connection con = null;
try{
System.out.println("start");
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
System.out.println("JDBC driver loaded");
con = DriverManager.getConnection(
"jdbc:mysql://localhost/zhaoding ?user=zhaoding&password=zhaoding");
System.out.println("Database connection established");
} 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 unknow 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 a lot for your time.
Ying
---------------------------------
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup