这样不好,result需要和connection绑在一起的,如果这样传递rs,那么connection也不能断,一个连接要占用很久的说connection一旦断掉,传过去的rs也白瞎了
解决方案 »
- hql 语句?
- 请问现在jsp asp php哪个用的多 比较好?
- 求救:struts2中的标签不识别"?"
- commons-fileupload如何限制上传速度?
- Hibernate为什么报这个错误?
- spring hibernate 整合 事务 传播性 问题??
- hibernate执行sql语句
- j2ee类库官方文档能下载吗?
- -------- session is closed -----------
- spring中HibernateTemplate的事务问题(100分)
- 关于在SPRING中用QUARTZ的问题
- oracle中自带的web应用服务器不能加载web.xml这个配置文件吗?
public static ArrayList delRes(String sql) {
ArrayList<LinkedHashMap> list = new ArrayList<LinkedHashMap>();
Connection conn = null;
PreparedStatement stmt = null;
ResultSetMetaData metaData=null;
try {
conn = ConDB.getCon();
stmt = (PreparedStatement) conn.prepareStatement(sql);
ResultSet result = stmt.executeQuery();
metaData=result.getMetaData();
while (result.next()) {
LinkedHashMap v = new LinkedHashMap();
for (int i = 1; i <= metaData.getColumnCount(); i++)
v.put(metaData.getColumnLabel(i),result.getObject(i));
list.add(v);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
用返回的list在页面上迭代显示就好了 程序连接过数据库后一定要关闭 否则服务器负载很大的 当多次使用或多人使用后服务器会down掉的 就算有连接池的话最好也关闭