无法从数据库循环读出下一条记录
如题,只能读出一条记录,代码如下:
public synchronized ArrayList getOkFile(String SEQUENCE) {
String sql = "SELECT T_SIG_INFO.FLOW_ID AS ID FROM T_SIG_PROCESS,T_SIG_INFO where T_SIG_PROCESS.FLOW_ID=T_SIG_INFO.FLOW_ID AND T_SIG_INFO.SIGNOK_NUM=T_SIG_INFO.SIG_NUM AND T_SIG_PROCESS.SEQUENCE= ' "
+SEQUENCE+ " 'AND T_SIG_PROCESS.IS_ACCEPT= '0 ' ";
ResultSet rs1=null;
ResultSet rs2=null;
ArrayList alRet = new ArrayList();
String FLOW_ID;
try {
openConnection();
openStatement();
rs1 = query(sql);
if(rs1 != null){
while(rs1.next()){//问题所在:此处循环只能一次
FLOW_ID=rs1.getString( "ID ");
Sig_InfoModel m = new Sig_InfoModel();
sql = "SELECT BUILDER,FILE_NAME,TO_CHAR(SIG_BEGIN, 'yyyy-mm-dd hh24:mi ') AS SIG_BEGIN FROM T_SIG_INFO where FLOW_ID= ' "+FLOW_ID+ " ' ";
try {
rs2 = query(sql);
if (rs2 != null) {
if(rs2.next()) {
m.setFlow_builder(rs2.getString( "BUILDER "));
m.setFile_name(rs2.getString( "FILE_NAME "));
m.setSig_begin(rs2.getString( "SIG_BEGIN "));
m.setFlow_id(FLOW_ID);
alRet.add(m);
}
}
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
return alRet;
}
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
finally {
try {
if (rs2!= null)
rs2.close();
if (rs1!= null)
rs1.close();
} catch (
SQLException ig) {
}
closeStatement();
closeConnection();
}
return null;
}
}
------解决方案--------------------你这样是不行的。
你打开了两次resultset。这是不允许的。
调用rs2 = query(sql)时就把rs1给close了。
再从rs1里取数据时就取不到了