当前位置: 代码迷 >> J2EE >> 用hibernate4连接数据库时,提醒No suitable driver found for jdbc:mysql://localhost:3306/te
  详细解决方案

用hibernate4连接数据库时,提醒No suitable driver found for jdbc:mysql://localhost:3306/te

热度:63   发布时间:2016-04-22 00:52:19.0
用hibernate4连接数据库时,提示No suitable driver found for jdbc:mysql://localhost:3306/te
刚接触hibernate,这个问题纠结了一天了,网上各种方法都试过了,依旧提示
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输出:
HTML code
严重: 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 causejava.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内容:
XML code
<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>
  相关解决方案