I tried several different ways such that Tomcat loads the MySQL drivers when running my web application. I'm using Ubuntu 8.04, and the libraries come from the libmysql-java package. They are located in the directory shown below:
~$ ls /usr/share/java/mysql* /usr/share/java/mysql-connector-java-5.1.5.jar
My CLASSPATH includes this file:
~$ echo $CLASSPATH .:/usr/lib/jvm/java-6-sun/bin:/usr/local/tomcat/lib/servlet-api.jar:/usr/share/java/mysql-connector-java-5.1.5.jar
I even put a copy of the .jar file in my WEB-INF/lib/ directory in my web app:
/usr/local/tomcat/webapps/ohms/WEB-INF/lib$ ls mysql-connector-java-5.1.5.jar
After making these changes, I restart Tomcat, re-compile my classes, restart Tomcat again. Also, I am importing the necessary libraries using import java.sql.*;
However I am still getting the java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
error when it runs the line Class.forName("com.mysql.jdbc.Driver").newInstance();
What am I doing wrong here?