Alexis Alexis - 20 days ago 7
Java Question

mysql-connector strange behaviour in Tomcat

I am trying to deploy an app with tomcat.Everything works fine, except that i expected to have an error after deleting the connector file(mysql-connector-java-5.1.40) from the WEB-INF>lib directory, but,surprise, is still working without it. So, my question is if Tomcat is saving the conector elsewhere(i ve searched in Tomcat directories and found nothing). To start the Tomcat i use the startup.bat from bin directory of Tomcat.
My simple code for mysql db connection:

public void jspInit() throws JSPException{
try{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
pst.con.prepareStatement("insert into employee values(?,?,?)");
}
catch(Exception e{
e.printStackTrace();
}

}

Answer

If you left Tomcat running as you deleted the MySQL driver jar, Tomcat will nevertheless have the Java bytecode for it loaded in the JVM. Did you restart Tomcat when you deleted the jar?

UPDATE

Look for...

  • A copy of the JDBC driver jar in some shared classpath location, e.g. Tomcat/shared/lib
  • A second copy of the JDBC driver jar (with a different name) in your webapp
  • Do you perhaps have a CLASSPATH environment variable set on this machine? Perhaps from another project?
Comments