Session session = null;
Connection conn = null;
Statement statement = null;
try {
session = sessionFactory.openSession();
conn = session.connection();
statement = conn.createStatement();
String cddm = "";
ResultSet result = statement.executeQuery(sql);
List list = new ArrayList();
int j = 0;
boolean done= true;
ResultSetMetaData md = result.getMetaData();
while (result.next()) {
j++;
done = true;
HashMap hm = new HashMap();
if (done){
for (int i = 1; i <= md.getColumnCount(); i++) {
hm.put(md.getColumnName(i).toUpperCase(), result
.getString(i));
}
list.add(hm);
}
}
result.close();
return (list);
} catch (SQLException e) {
throw (new CarelessException("使用Hibernate(SQL)访问数据库时异常", e));
} finally {
if (statement != null) {
try {
statement.close();
} catch (Exception e) {
logger.getLogger().error( "HibernateAccessor exceptionA:" + e );
logger.getLogger().error(ExceptionMsg.getMsg(e));
}
}
if (session != null) {
session.close();
}
}