用一个group by 的sql查询,但是发现查询出来的rs只要一操作(比如rs.next)就说我rs已经关闭,报sqlException的错误。
直接用sql是可以查询出来结果的。也已确认已经得到连接conn了。不知咋回事,请高手指教。 /**
* group by 语句查询现在的回访数量
* @return
* @throws Exception
*/
public ArrayList selectSummary() {
ArrayList al = new ArrayList();
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
String sql = "select CALL_RESULT_DESCRIPTION,count(*) from OBT_TEST_TABLE where CALL_RECORD_TYPE <> 0 group by CALL_RESULT_DESCRIPTION";
CommonLogger.logger.debug(sql);
try {
conn = AppHandle.getHandle("newCallback").getConnection();
} catch (Exception e1) {
e1.printStackTrace();
}
CommonLogger.logger.debug(conn.toString());
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
CommonLogger.logger.debug(rs.getString(1));
while (rs.next()) {
al.add(rs.getString(1));
al.add(rs.getString(2));
al.add("1");
CommonLogger.logger.debug("第一列的值");
}
} catch (SQLException e) {
e.printStackTrace();
CommonLogger.logger.debug("selectSummary方法:查询select SQLException");
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
CommonLogger.logger.debug("select方法:查询select出现异常,finally里面关资源也还是出错了");
}
} return al;
}
直接用sql是可以查询出来结果的。也已确认已经得到连接conn了。不知咋回事,请高手指教。 /**
* group by 语句查询现在的回访数量
* @return
* @throws Exception
*/
public ArrayList selectSummary() {
ArrayList al = new ArrayList();
Statement stmt = null;
ResultSet rs = null;
Connection conn = null;
String sql = "select CALL_RESULT_DESCRIPTION,count(*) from OBT_TEST_TABLE where CALL_RECORD_TYPE <> 0 group by CALL_RESULT_DESCRIPTION";
CommonLogger.logger.debug(sql);
try {
conn = AppHandle.getHandle("newCallback").getConnection();
} catch (Exception e1) {
e1.printStackTrace();
}
CommonLogger.logger.debug(conn.toString());
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
rs.next();
CommonLogger.logger.debug(rs.getString(1));
while (rs.next()) {
al.add(rs.getString(1));
al.add(rs.getString(2));
al.add("1");
CommonLogger.logger.debug("第一列的值");
}
} catch (SQLException e) {
e.printStackTrace();
CommonLogger.logger.debug("selectSummary方法:查询select SQLException");
} finally {
try {
if (rs != null) rs.close();
if (stmt != null) stmt.close();
if (conn != null) conn.close();
} catch (SQLException e) {
e.printStackTrace();
CommonLogger.logger.debug("select方法:查询select出现异常,finally里面关资源也还是出错了");
}
} return al;
}
解决方案 »
- 用jsp做了个系统,怎么被非法访问
- 有搞JSF开发的兄弟吗?
- 求一个多条件查询的例子?
- 请教JSP加TOMCAT加MYSQL的BEAN连接问题,小弟是初学者,问题不难,望各位大侠指点一二,在下万分感激!!!
- 如何在页面中显示源代码
- 麻烦啊
- 高分求救~!关于mozilla的返回问题~!只要解决,500分送~!
- Juilder中可以引入zip文件吗(?)
- 各位请问哪里有免费可靠的支持JSP的空间,想找一个用来学习。(NULL)
- Inprise Application Server 跟 Borland AppServer是一个东东吗?
- 关于displaytag的两个问题
- grouby 查询出的结果 不能操作 请高手指教
CommonLogger.logger.debug(rs.getString(1)); 注释掉
CommonLogger.logger.debug(rs.getString(1));
把这2句话干掉,看还有问题么?