首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

hibernate联接mysql报错

2012-12-15 
hibernate连接mysql报错环境hibernate4.1.2,mysql5.0.8我的mysql地址是没有错的,我简单的用JDBC测试过地址

hibernate连接mysql报错
环境hibernate4.1.2,mysql5.0.8

我的mysql地址是没有错的,我简单的用JDBC测试过地址,但是配到hibernate.cfg.xml一运行就说我地址错误,请各位大侠帮忙解决问题谢谢..

hibernate.cfg.xml配置
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
    <!-- Database connection settings -->
    <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
    <property name="connection.username">root</property>
    <property name="connection.password">root</property>

    <!-- JDBC connection pool (use the built-in) -->
    <property name="connection.pool_size">1</property>

    <!-- SQL dialect -->
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

    <!-- Enable Hibernate's automatic session context management -->
    <!--<property name="current_session_context_class">thread</property>

    --><!-- Disable the second-level cache  -->
    <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

    <!-- Echo all executed SQL to stdout -->
    <property name="show_sql">true</property>

    <!-- Drop and re-create the database schema on startup -->
    <!--<property name="hbm2ddl.auto">update</property>

--><mapping resource="com/bjsxt/hibernate/model/student.hbm.xml" />
</session-factory>
</hibernate-configuration>


错误信息:
ERROR: No suitable driver found for jdbc:mysql://localhost/hibernate
Exception in thread "main" org.hibernate.exception.JDBCConnectionException: Could not open connection
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:131)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:304)
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 Test.main(Test.java:23)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/hibernate
at java.sql.DriverManager.getConnection(DriverManager.java:602)


at java.sql.DriverManager.getConnection(DriverManager.java:154)
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)
... 5 more

[解决办法]
No suitable driver found for jdbc:mysql://localhost/hibernate
没得合适的驱动!!你的驱动加没?
[解决办法]
驱动包没有添加
[解决办法]
谢谢哈我解决了
[解决办法]
端口?
[解决办法]
说下解决方法把,我也是用的4.1.2跟楼主一样的问题,但是用hibernate3就没有问题!
[解决办法]
哈哈,问题解决了,为了方便以后遇到这个问题的童鞋们,我还是说下解决方法。
其实是驱动包过时了。
很多人一直都是用的mysql-connector-java-5.0.8.jar这个驱动包,然而hibernate4需要更新的mysql驱动包,现在最新的驱动包是5.1.19,但是在mysql官方任然是5.0.8,需要点击最新版本才能看见5.1.19那个mysql驱动。

至于什么方言 MySQL5Dialect ,我看了hibernate4.1.2的devgaide,里面说的根本就不是那么一会事儿,MySQLDialect在hibernate4.1.2里面仍然可以使用哈。

引用:
说下解决方法把,我也是用的4.1.2跟楼主一样的问题,但是用hibernate3就没有问题!

[解决办法]
楼主正解,按照楼主的方法解决了,就是驱动版本太低

热点排行