简体   繁体   English

mysql-connector在Tomcat中的奇怪行为

[英]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. 我正在尝试使用tomcat部署应用程序。一切正常,除了我希望从WEB-INF> lib目录删除连接器文件(mysql-connector-java-5.1.40)后出现错误,但是,令人惊讶,如果没有它,仍然可以工作。 So, my question is if Tomcat is saving the conector elsewhere(i ve searched in Tomcat directories and found nothing). 因此,我的问题是Tomcat是否将连接器保存在其他位置(我已经在Tomcat目录中搜索但未找到任何内容)。 To start the Tomcat i use the startup.bat from bin directory of Tomcat. 要启动Tomcat,我使用Tomcat的bin目录中的startup.bat。 My simple code for mysql db connection: 我的mysql db连接的简单代码:

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();
        }

    }

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. 如果在删除MySQL驱动程序jar时让Tomcat运行,则Tomcat仍将在JVM中加载其Java字节码。 Did you restart Tomcat when you deleted the jar? 删除jar时是否重新启动了Tomcat?

UPDATE 更新

Look for... 寻找...

  • A copy of the JDBC driver jar in some shared classpath location, eg Tomcat/shared/lib 某些共享类路径位置中的JDBC驱动程序jar的副本, 例如 Tomcat / shared / lib
  • A second copy of the JDBC driver jar (with a different name) in your webapp Web应用程序中的JDBC驱动程序jar的第二个副本(具有不同的名称)
  • Do you perhaps have a CLASSPATH environment variable set on this machine? 您是否在此计算机上设置了CLASSPATH环境变量? Perhaps from another project? 也许来自另一个项目?

You can try a jmap -histo <PID> if you have jmap on your system to make sure your have MySQL driver class actually loaded . 如果您的系统上有jmap,可以尝试使用jmap -histo <PID>来确保已实际加载MySQL驱动程序类。

While your application is running you can also try something like lsof |grep ".*mysql.*jar" to see if there's a jar but remember you could have sources somewhere too. 当您的应用程序运行时,您也可以尝试使用lsof |grep ".*mysql.*jar"来查看是否存在jar,但请记住您也可以在某处找到源。 (in that case just grep or find it ) (在这种情况下,只需grep或find它)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM