Hi everyone,
I got the following exception when my application was trying to close the session:
15:19:14,802 DEBUG SessionImpl:3201 - disconnecting session
15:19:14,838 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: Already closed.
at org.apache.commons.dbcp.PoolableConnection.close(PoolableConnection.java:111)
at net.sf.hibernate.connection.DBCPConnectionProvider.closeConnection(DBCPConnectionProvider.java:48)
at net.sf.hibernate.impl.BatcherImpl.closeConnection(BatcherImpl.java:275)
at net.sf.hibernate.impl.SessionImpl.disconnect(SessionImpl.java:3217)
at net.sf.hibernate.impl.SessionImpl.close(SessionImpl.java:547)
at com.accucast4.customerdatasource.DbCustomerDataSourceImp.deleteRecipientList(DbCustomerDataSourceImp.java:2777)
at com.accucast3.buildmanager.TrialBuilder.run(TrialBuilder.java:226)
I might have done something wrong on my coding level for managing JDBC connection manually. Here is the code that is causing problem:
Code:
Session session = null;
Connection conn = null;
PreparedStatement ps = null;
StringBuffer deleteString = null;
int deleteCount = 0;
try {
String deleteSql = "something delete sql";
logger.debug("delete sql statement:" + deleteSql);
session = (Session)getConnection();
conn = session.connection();
ps = conn.prepareStatement(deleteSql);
ps.setLong(1, id);
deleteCount = ps.executeUpdate();
conn.commit();
} catch (HibernateException he){
logger.error("unable to delete something", he);
try {
if (conn != null){
conn.rollback();
}
} catch (SQLException sqlex){
logger.error("unable to rollback something", sqlex);
}
throw new SomeException ("unable to delete something",
1, he);
} catch (SQLException sqlError){
logger.error("unable to delete something", sqlError);
try {
if (conn != null){
conn.rollback();
}
} catch (SQLException sqlex){
logger.error("unable to rollback delete something", sqlex);
}
throw new SomeException ("unable to delete something",
1, he);
} finally {
try {
if (ps != null)
ps.close();
} catch (SQLException sqlexps){
logger.error("unable to close preparedstatement", sqlexps);
}
try {
if (conn != null){
conn.close();
}
} catch (SQLException sqlex){
logger.error("unable to close session", sqlex);
}
try {
if (session != null){
session.flush();
session.close();
}
} catch (HibernateException he){
logger.error("unable to close session", he);
}
}
return deleteCount;
My question is: do I need to do conn.close and session.close or should I just code with session.close?? I would really appreciate if anyone can give me some inputs on this question. Thanks.
Vivian Fonger