weixin_42362297
2010-04-07 21:28
浏览 713
已采纳

Hibernate连接不上Mysql数据库

Hibernate 3.5 + Eclipse 3.4 sdk
我的hibernate.cfg.xml配置如下:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">


com.mysql.jdbc.Driver
jdbc.mysql://localhost:3306/myproject
root
123456
1
org.hibernate.dialect.MySQLDialect
thread
org.hibernate.cache.NoCacheProvider
true
create



运行出错:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1463)
at ch03.hibernate.Test.main(Test.java:11)
Caused by: java.sql.SQLException: No suitable driver found for jdbc.mysql://localhost:3306/myproject
at java.sql.DriverManager.getConnection(DriverManager.java:602)
at java.sql.DriverManager.getConnection(DriverManager.java:154)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:133)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 5 more
不得其解。很郁闷。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • scriptguy 2010-04-08 20:22
    已采纳

    jdbc.mysql://localhost:3306/myproject
    改为:jdbc[color=red]:[/color]mysql://localhost:3306/myproject

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • iteye_13460 2010-04-07 23:00

    [quote]Caused by: java.sql.SQLException: No suitable driver found for jdbc.mysql://localhost:3306/myproject [/quote]

    [color=red][size=x-large]首先,你要去看提示的错误,虽然提示的错误不一定指的很正确,但有帮助.

    其次,你这个错误是说没找到JDBC Driver.你要知道JDBC Driver有四种类型,我们平常使用的是第四类,所以你要确保你有正确的JDBC Driver.
    不同的JDBC驱动包(通常是jar文件),你的JDBC URL的格式是不一样的.也就是[/size]:[[/color]quote]jdbc.mysql://localhost:3306/myproject[/quote]
    这个的写法是不一样的...

    希望对你有帮助...

    评论
    解决 无用
    打赏 举报
  • WdWheyr 2010-04-08 09:12

    看一下你的mysql-connector-java-5.1.6-bin.jar包是否放在web应用的lib或%JAVA_HOME%\jre\lib \ext文件夹中

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题