Hi guys!
I'm trying to use Hibernate in old JDBC way, but for some reason, when
calling executeQuery() an exception:
java.sql.SQLException: Statement has already been closed
Any idea about this?
Thanks,
Horatiu
Code:
HashMap<Long, String> typesHash = new HashMap<Long,String>();
String sqlQuery = "SELECT " +
" pcf.field_sk, atc.data_type "+
"FROM " +
" package_criteria_fields pcf, all_tab_columns atc "+
"WHERE "+
" admin_type = "+adminType+
" AND " +
" benefit_g20sk = "+benefitType+
" AND " +
" atc.table_name = pcf.table_name " +
" AND " +
" atc.column_name = pcf.column_name order by pcf.field_sk ";
Session session = this.getSession();
try {
Connection connection = session.connection();
try {
Statement statement = connection.createStatement();
ResultSet rs = null;
try {
rs = statement.executeQuery(sqlQuery);
while(null != rs && rs.next()){
typesHash.put(new Long(rs.getInt(0)), rs.getString(1));
}
}catch(Exception e){
logger.error("Cannot retrieve the types of criteria fields from the database.");
//@todo a system error should be thrown.
throw new RuntimeException("Cannot retrieve the types of criteria fields from the database.");
}finally {
statement.close();
if(null != rs){
rs.close();
}
}
}
catch (HibernateException e) {
connection.rollback();
logger.error("Cannot create a Statement object from Connection.");
//@todo a system error should be thrown.
throw new RuntimeException("Cannot create a Statement object from Connection.");
}
catch (SQLException e) {
connection.rollback();
logger.error("Cannot create a Statement object from Connection.");
//@todo a system error should be thrown.
throw new RuntimeException("Cannot create a Statement object from Connection.");
}
}
catch (SQLException e) {
logger.error("Cannot get a Connection from the Hibernate Session.");
//@todo a system error should be thrown.
throw new RuntimeException("Cannot get a Connection from the Hibernate Session.");
}
finally {
session.close();
}