使用SSH出现异常:org.hibernate.exception.GenericJDBCException: Could not open connectio

树上跳舞的鱼 2016-04-11 10:25:04
我用的是spring4.1.4+hibernate4.2.21,运行时出现如下异常:
org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:544)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:457)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:276)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
.....
Caused by: org.hibernate.exception.GenericJDBCException: Could not open connection
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.obtainConnection(LogicalConnectionImpl.java:221)
at org.hibernate.engine.jdbc.internal.LogicalConnectionImpl.getConnection(LogicalConnectionImpl.java:157)
at org.hibernate.internal.SessionImpl.connection(SessionImpl.java:427)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:450)
... 99 more
Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1215)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
......
纠结了一整天了,都快崩溃了!!网上也没搜索到正确的解决方案,望大神们高手们来指导指导解我烦扰!!

...全文
2306 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
树上跳舞的鱼 2016-04-12
  • 打赏
  • 举报
回复
引用 8 楼 zw0283 的回复:
还有后边那句。。刚刚没看见:Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: YES) 是不是密码什么的错了
密码没有错!不知道是不是jar包冲突的问题。这两天被这个问题搞得心神不宁的,烦死了
树上跳舞的鱼 2016-04-12
  • 打赏
  • 举报
回复
自己顶上去,别沉别沉......快来人啊,哪怕来一个人指导下也好啊
树上跳舞的鱼 2016-04-12
  • 打赏
  • 举报
回复
是这样写的没错。问题应该不是出在这里,我怀疑是jar包冲突,但没法确定是哪些jar包有冲突。。
项目所有jar包如下:


  • 打赏
  • 举报
回复
<prop key="hibernate.connection.jdbcUrl">jdbc:mysql://localhost:3306/books_system?useUnicode=true&characterEncoding=UTF-8</prop> 这个玩意应该不是这么写的吧
zw0283 2016-04-12
  • 打赏
  • 举报
回复
首先。。你的配置文件贴上来的话最好用编辑器里的那个标签扩上,要不看着很难受。 第一句话有:Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection。提取一下,就是Could not open Hibernate Session for transaction因为Could not open connection,就是你的跟数据库的连接处问题了。先查配置文件,然后看看有没有jar包冲突什么的。你那个钥匙新项目的话,不要一次加那么多jar包。。用哪个加哪个。。否则很不好排错的。。
zw0283 2016-04-12
  • 打赏
  • 举报
回复
还有后边那句。。刚刚没看见:Caused by: java.sql.SQLException: Access denied for user 'sa'@'localhost' (using password: YES) 是不是密码什么的错了
  • 打赏
  • 举报
回复
hibernate.connection.username
树上跳舞的鱼 2016-04-11
  • 打赏
  • 举报
回复
都没有人来吗?顶顶顶。。高手高手快点来!!!
树上跳舞的鱼 2016-04-11
  • 打赏
  • 举报
回复
这是我的配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> <bean id="dataSource" destroy-method="close" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver" /> <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/books_system?useUnicode=true&characterEncoding=UTF-8" /> <property name="user" value="Jerry" /> <property name="password" value="angiechiu" /> <property name="maxPoolSize" value="40" /> <property name="minPoolSize" value="1" /> <property name="initialPoolSize" value="1" /> <property name="maxIdleTime" value="60" /> <property name="checkoutTimeout" value="2000" /> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource" /> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.connection.driverClass">com.mysql.jdbc.Driver</prop> <prop key="hibernate.connection.jdbcUrl">jdbc:mysql://localhost:3306/books_system?useUnicode=true&characterEncoding=UTF-8</prop> <prop key="hibernate.connection.user">Jerry</prop> <prop key="hibernate.connection.password">angiechiu</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> <property name="mappingLocations"> <value>classpath:com/pb/entity/*.hbm.xml</value> </property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true" /> <tx:method name="validate*" read-only="true" /> <tx:method name="doLogin" read-only="true" /> <tx:method name="doRegister" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut expression="execution(* com.pb.service.impl.*.*(..))" id="service" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="service" /> </aop:config> <context:component-scan base-package="com.pb"> <context:include-filter type="regex" expression="com.pb.dao.impl.*" /> <context:include-filter type="regex" expression="com.pb.service.impl.*" /> </context:component-scan> ...... </beans>

81,092

社区成员

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

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