一个郁闷了我一个星期的问题(hibernate),谢谢,解决就给分,~~
在用hibernate +struts做一个查询,数据库用的mysql
多次刷新一个查询页面后,就出先这个异常:
net.sf.hibernate.exception,JDBCConnectionException:Cannot open connection
at net.sf.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:66)
......
"Cannot open connection"
感觉是数据库没有关闭,最后导致连接数过多,最后无法打开连接,
但是我的session都是关闭了的
下面是部分代码片段:
.......
Transaction tx = null;
Session session1 = HbmSessionFactory.openSession();
try {
tx = session1.beginTransaction();
...
session1.save(obj);
tx.commit();
}
catch (HibernateException ex) {
ex.printStackTrace();
try {
tx.rollback();
}
catch (HibernateException ex1) {
ex1.printStackTrace();
}
}finally{
try {
session1.close();
}
catch (HibernateException ex2) {
ex2.printStackTrace();
}
}
....
请大家一起讨论~~