No suitable driver found for jdbc:mysql://localhost:3306/test
用的是hibernate4,以下几个应该注意的地方都检查过了,没有问题:
1、jdbc-connector的jar包添加到WEB-INF/lib下;
2、url格式正确;
3、jdbc-connector的jar包添加到javahome/jre/lib/ext下。
以前用hibernate3访问数据库的时候没有出这问题啊。求解答;以下是console输出:
严重: Servlet.service() for servlet [dispatcher] in context with path [/springMVC] threw exception [Request processing failed; nested exception is org.hibernate.exception.JDBCConnectionException: Could not open connection] with root cause
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)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:169)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doBegin(JdbcTransaction.java:67)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.begin(AbstractTransactionImpl.java:160)
at org.hibernate.internal.SessionImpl.beginTransaction(SessionImpl.java:1363)
at cn.edu.tju.lxd.Checkvalid.isvalid(Checkvalid.java:16)
at cn.edu.tju.lxd.login.handleRequest(login.java:22)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
以下是hibernate.cfg.xml内容:
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="connection.username">inter</property>
<property name="connection.password">password</property>
<mapping resource="cn/edu/tju/user/copy/User.hbm.xml" />
</session-factory>
</hibernate-configuration>
7 个解决方案
#1
jdbc:mysql://127.0.0.1:3306/test
试下这样、
试下这样、
#2
不行的。
#3
话说你有添加 mysql的jar 包吗?
#4
那确定你的mysql的jar和你mysql的版本对应了?
#5
找到错误了。是hibernate版本问题,我把hibernate4换成了hibernate3,然后就没报错了。。。
#6
这个方法有用,谢谢。
#7
jdbc:mysql://127.0.0.1:3306/test 用这个或许就能成功
#1
jdbc:mysql://127.0.0.1:3306/test
试下这样、
试下这样、
#2
不行的。
#3
话说你有添加 mysql的jar 包吗?
#4
那确定你的mysql的jar和你mysql的版本对应了?
#5
找到错误了。是hibernate版本问题,我把hibernate4换成了hibernate3,然后就没报错了。。。
#6
这个方法有用,谢谢。
#7
jdbc:mysql://127.0.0.1:3306/test 用这个或许就能成功