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

baidu_29966643 2015-09-07 10:54:30
九月 07, 2015 10:31:46 下午 org.hibernate.annotations.common.Version <clinit>
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 <clinit>
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 <init>
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 <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
九月 07, 2015 10:31:46 下午 org.hibernate.validator.util.Version <clinit>
信息: 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
...全文
220 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
baidu_29966643 2015-09-08
  • 打赏
  • 举报
回复
引用 5 楼 u012459865 的回复:
No suitable driver found for jdbc:mysql://localhost:3306/db_database10 (1)LZ你的数据库db_database10有没有创建? (2)MYSQL JAR包有没有添加? (3)LZ你的数据库有没有启动?
你说的3条都做了,我在这边写了一个简单的jsp连接数据库测试了一下,发现能连得上,然而Hibernate就连不上了是不是缺少什么
猫神jdx 2015-09-08
  • 打赏
  • 举报
回复
No suitable driver found for jdbc:mysql://localhost:3306/db_database10 (1)LZ你的数据库db_database10有没有创建? (2)MYSQL JAR包有没有添加? (3)LZ你的数据库有没有启动?
baidu_29966643 2015-09-08
  • 打赏
  • 举报
回复
sessionFactory是自动生成的,应该不会出问题吧....... jar包应该没问题吧,直接连接不用hibernate是能连得上的
baidu_29966643 2015-09-08
  • 打赏
  • 举报
回复
配置如下 <hibernate-configuration> <session-factory> <!-- 数据库驱动 --> <property name="connect.driver_class"> com.mysql.jdbc.Driver </property> <!-- 数据库连接的URL --> <property name="connection.url"> jdbc:mysql://localhost:3306/db_database10 </property> <!-- 数据库连接用户名 --> <property name="connection.username">root</property> <!-- 数据库连接密码 --> <property name="connection.password">123321</property> <!-- Hibernate方言 --> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <!-- 打印sql语句 --> <property name="show_sql">true</property> <!-- 映射文件 --> <mapping resource="com/xdc/Product/Product.hbm.xml" /> </session-factory> </hibernate-configuration>
QSEN1024 2015-09-07
  • 打赏
  • 举报
回复
好像你MySQL的jar包版本的问题。 你MySQL用的什么版本的,看看你的方言设置的正确么?
qq_20062767 2015-09-07
  • 打赏
  • 举报
回复
你好,我发现了两个问题。第一:你的数据库连接不上,原因可能是你的数据库连接串有问题,或者你没有把数据库驱动的包导入。 第二:你的sessionFactory为null,原因可能是你的程序写的有问题,取得sessionFactory的那个类写的有问题。

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧