简体   繁体   English

找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序

[英]No suitable driver found for jdbc:mysql://localhost:3306/test

When i try to run my JSF application on Tomcat 7, it throws this exception. 当我尝试在Tomcat 7上运行我的JSF应用程序时,它将引发此异常。

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. 如果我在创建EntitiyManagerFactory之前添加此行,则可以正常工作。

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"); 我的应用程序也可以在tomcat 6上正常工作,而无需添加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. 第一个也是实际的解决方案:尝试使用Hibernate 4.1.0和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 . 在最终跌入https://forum.hibernate.org/viewtopic.php?p=2454336之前,我在Hibernate 4.1.2上遇到了此问题。 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. 据我所知,Tomcat的更高版本(针对DeviceManager的漏洞性质的修复程序)与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: 其他解决方法是像Brad Whitaker的回答中那样显式调用驱动程序的注册,或者通过在$ CATALINA_HOME / conf / server的侦听器定义中添加driverManagerProtection="false"来确保JreMemoryLeakPreventionListener没有保护DriverManager。 xml-即:

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

I encountered this same problem when I migrated a working .war from Tomcat 5.5 and Java 6 to Tomcat 7 and Java 7. My previously working .war started throwing "java.sql.SQLException: No suitable driver found for jdbc:sqlserver...". 我从Tomcat 5.5和Java 6迁移到Tomcat 7和Java 7时,遇到了同样的问题。我以前的.war开始抛出“ java.sql.SQLException:找不到适用于jdbc:sqlserver的驱动程序... ”。 I was able to resolve by simply adding 我能够通过简单地添加来解决

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");

immediately before invoking 在调用之前

java.sql.DriverManager.getConnection("myUrl");

I'm aware that documentation says this additional call is not required with the jdbc4 driver, but this fixed my problem. 我知道文档说明jdbc4驱动程序不需要此附加调用,但这已解决了我的问题。 The driver jar (sqljdbc4.jar) was located in WEB-INF/lib of my .war. 驱动程序jar(sqljdbc4.jar)位于我的.war的WEB-INF / lib中。

问题是驱动程序类在您的应用程序运行时不可用,请将驱动程序jar放入/WEB-INF/lib

在某些服务器(jboss,glassfish)上,我还必须将驱动程序jar放入服务器的默认库文件夹中。

I have similar issue. 我有类似的问题。 It is solved by upgrading hibernate to 4.1.4final. 通过将休眠模式升级到4.1.4final可以解决此问题。

暂无
暂无

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

相关问题 错误:找不到适用于jdbc:mysql:// localhost:3306 / test的驱动程序 - ERROR: No suitable driver found for jdbc:mysql://localhost:3306/test 找不到适用于jdbc:mysql // localhost:3306 / test的驱动程序 - No suitable driver found for jdbc:mysql//localhost:3306/test JDBC JAVA找不到适合的驱动程序jdbc:mysql:// localhost:3306 / voting - JDBC JAVA No suitable driver found for jdbc:mysql://localhost:3306/voting 发现此错误“没有找到适合 jdbc:mysql//localhost:3306/student 的驱动程序” - Found this error "No suitable driver found for jdbc:mysql//localhost:3306/student" 如何解决:找不到适合jdbc的驱动:mysql://localhost:3306/sampledb - How to solve: No suitable driver found for jdbc:mysql://localhost:3306/sampledb 找不到适用于jdbc:mysql:// localhost:3306 / jpa的驱动程序 - No suitable driver found for jdbc:mysql://localhost:3306/ jpa 找不到适用于jdbc:mysql / localhost:3306 / world的驱动程序 - No suitable driver found for jdbc:mysql/localhost:3306/world Eclipse - Hibernate:没有为jdbc找到合适的驱动程序:mysql:// localhost:3306 / hibernatedb - Eclipse - Hibernate : No suitable driver found for jdbc:mysql://localhost:3306/hibernatedb 找不到适用于jdbc:mysql // localhost:3306 / demo的驱动程序吗?useSSL = false - No suitable driver found for jdbc:mysql//localhost:3306/demo?useSSL=false SQLException:找不到适用于jdbc:mysql:// localhost:3306 / dbname的驱动程序 - SQLException: No suitable driver found for jdbc:mysql://localhost:3306/dbname
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM