找不到适合jdbc的驱动程序:mysql:// localhost:3306 / test [英] No suitable driver found for jdbc:mysql://localhost:3306/test

查看:134
本文介绍了找不到适合jdbc的驱动程序:mysql:// localhost:3306 / test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Tomcat 7上运行我的JSF应用程序时,它会引发此异常。

 原因:java.sql.SQLException:找不到适合jdbc的驱动程序:mysql:// localhost:3306 / test 
at java.sql.DriverManager.getConnection(未知源)
在java.sql.DriverManager.getConnection(未知源)
在org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl。 getConnection(DriverManagerConnectionProviderImpl.java:192)
at org.hibernate.internal.AbstractSessionImpl $ NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:278)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection( LogicalConnectionImpl.java:297)
... 51 more

创建EntitiyManagerFactory,它工作正常。

  Class.forName(com.mysql.jdbc.Driver); 
emf = Persistence.createEntityManagerFactory(manager1);

我的依赖关系是

 <依赖性> 
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-entitymanager< / artifactId>
< version> 4.1.2.Final< / version>
< /依赖关系>

< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 5.1.19< / version>
< /依赖关系>

另外我的应用程序可以正常工作,不需要添加 Class.forName( com.mysql.jdbc.Driver);



有什么想法解决这个问题?谢谢

解决方案

第一个真正的解决方案:尝试使用Hibernate 4.1.0和4.1.3.Final。
$ b

我在Hibernate 4.1.2上遇到了这个问题,最终在 https://forum.hibernate.org/viewtopic.php?p=2454336 。据我所知,在Tomcat的后续版本(针对DeviceManager的漏洞修复)和Hibernate 4.1.2之间存在一些不兼容的问题。



其他解决方法是明确调用驱动程序的注册,就像在Brad Whitaker的回答中一样,或者通过添加 driverManagerProtection =false添加到$ CATALINA_HOME / conf / server.xml中的Listener定义 - 即:

$ p $ < Listener className = org.apache.catalina.core.JMeMemoryLeakPreventionListenerdriverManagerProtection =false>


When i try to run my JSF application on Tomcat 7, it throws this exception.

Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/test
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:192)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:278)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
... 51 more

If I add this line before creating EntitiyManagerFactory, it works fine.

Class.forName("com.mysql.jdbc.Driver");
emf = Persistence.createEntityManagerFactory("manager1");

My dependencies are

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.2.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.19</version>
    </dependency>

Also my application works fine tomcat 6, without adding Class.forName("com.mysql.jdbc.Driver");

Any idea to solve this problem? Thanks

解决方案

First and real solution: Try with Hibernate 4.1.0 and 4.1.3.Final.

I ran into this issue on Hibernate 4.1.2 before eventually stumbling across https://forum.hibernate.org/viewtopic.php?p=2454336. As far as I can see, it's a bit of an incompatibility between the later versions of Tomcat (In its fixes for the leaky nature of the DeviceManager) and Hibernate 4.1.2.

The other workarounds are to invoke the registration of the driver explicitly, as in Brad Whitaker's answer, or to make sure the JreMemoryLeakPreventionListener isn't protecting the DriverManager by adding driverManagerProtection="false" to the Listener definition in $CATALINA_HOME/conf/server.xml - that is:

<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" driverManagerProtection="false">

这篇关于找不到适合jdbc的驱动程序:mysql:// localhost:3306 / test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆