新手Hibernate写了个小程序,第一次运行报错如下,好像还有数据库连不上的问题,不知道该怎么改

九月 07, 2015 10:31:46 下午 org.hibernate.annotations.common.Version
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
九月 07, 2015 10:31:46 下午 org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.4.Final}
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Environment
INFO: HHH000206: hibernate.properties not found
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Configuration configure
INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Configuration addResource
INFO: HHH000221: Reading mappings from resource: com/xdc/Product/Product.hbm.xml
九月 07, 2015 10:31:46 下午 org.hibernate.cfg.Configuration doConfigure
INFO: HHH000041: Configured SessionFactory: null
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000148: No JDBC Driver class was specified by property hibernate.connection.driver_class
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: false
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [null] at URL [jdbc:mysql://localhost:3306/db_database10]
九月 07, 2015 10:31:46 下午 org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=root, password=****}
九月 07, 2015 10:31:46 下午 org.hibernate.engine.jdbc.internal.JdbcServicesImpl configure
WARN: HHH000342: Could not obtain connection to query metadata : No suitable driver found for jdbc:mysql://localhost:3306/db_database10
九月 07, 2015 10:31:46 下午 org.hibernate.dialect.Dialect
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
九月 07, 2015 10:31:46 下午 org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000422: Disabling contextual LOB creation as connection was null
九月 07, 2015 10:31:46 下午 org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
九月 07, 2015 10:31:46 下午 org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
九月 07, 2015 10:31:46 下午 org.hibernate.validator.util.Version
信息: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
九月 07, 2015 10:31:46 下午 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
信息: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
九月 07, 2015 10:31:46 下午 org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
信息: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
九月 07, 2015 10:31:47 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 08001
九月 07, 2015 10:31:47 下午 org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: No suitable driver found for jdbc:mysql://localhost:3306/db_database10
添加数据库失败!
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:1396)
at com.xdc.main.AddProduct.main(AddProduct.java:19)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/db_database10
at java.sql.DriverManager.getConnection(DriverManager.java:596)
at java.sql.DriverManager.getConnection(DriverManager.java:187)
at org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl.getConnection(DriverManagerConnectionProviderImpl.java:193)
at org.hibernate.internal.AbstractSessionImpl$NonContextualJdbcConnectionAccess.obtainConnection(AbstractSessionImpl.java:281)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:297)
... 5 more

配置如下


com.mysql.jdbc.Driver


jdbc:mysql://localhost:3306/db_database10

root

123321

org.hibernate.dialect.MySQLDialect

true


4个回答

No suitable driver found for jdbc:mysql://localhost:3306/db_database10
检查你的数据库的驱动和链接,防火墙等

baidu_29966643
baidu_29966643 不用hibernate是能连接的上数据库的,用了连不上,不知道什么原因
4 年多之前 回复

出现这样的情况,一般有四种原因:

一:连接URL格式出现了问题(Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/XX","root","XXXX")

二:驱动字符串出错(com.mysql.jdbc.Driver)

三:Classpath中没有加入合适的mysql_jdbc驱动(驱动要和你的数据库版本一致)

四:驱动jar包放的位置不对

wepwq70900
袁缺 非常感谢!
2 年多之前 回复

org.hibernate.exception.JDBCConnectionException: Could not open connection
可能是连接代码有错,仔细检查一下。可以百度一下,看看人家怎么写的

1:本地装了Mysql server
2:检查mysql驱动jar存在不

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问