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
不得其解。很郁闷。
jdbc.mysql://localhost:3306/myproject
改为:jdbc[color=red]:[/color]mysql://localhost:3306/myproject
[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]
这个的写法是不一样的...
希望对你有帮助...
看一下你的mysql-connector-java-5.1.6-bin.jar包是否放在web应用的lib或%JAVA_HOME%\jre\lib \ext文件夹中