我是这样获取链接和关闭的:
Session sess = HibernateSessionFactory.currentSession();
Connection con = sess.connection();
...
try {
Statement stm =con.createStatement();
ResultSet rs=stm.executeQuery(sql); //异常出现的位置
} catch (SQLException e1) {
e1.printStackTrace();
}
......HibernateSessionFactory.closeSession();
Session sess = HibernateSessionFactory.currentSession();
Connection con = sess.connection();
...
try {
Statement stm =con.createStatement();
ResultSet rs=stm.executeQuery(sql); //异常出现的位置
} catch (SQLException e1) {
e1.printStackTrace();
}
......HibernateSessionFactory.closeSession();
我测试了下:
在执行关闭之后,HibernateSessionFactory.closeSession();
这个连接还能继续使用,
Statement stm2=con.createStatement();
ResultSet rs2 = stm.executeQuery(sql);
既然你不用hibernate的方法。直接new 一个connection得了