PFB我使用的代码:
ResultSet rs1 = stmt.executeQuery("select dfd.document_id,dfd.country_id,dfi.folder_name from dossier_folder_documents dfd,dossier_folder_info dfi where dfd.fk_dossier_folder_id=dfi.pk_dossier_folder_id and dfd.is_core is null and dfd.action='N' and dfd.fk_dossier_basic_info_id in (select pk_dossier_id from dossier_basic_info where dossier_id= '"+vdlist.get(g)+"' and (dfd.document_id,dfi.folder_name) not in(select dfd.document_id,dfi.folder_name from dossier_folder_documents dfd,dossier_folder_info dfi where dfd.fk_dossier_folder_id=dfi.pk_dossier_folder_id and dfd.fk_dossier_basic_info_id in (select pk_dossier_id from dossier_basic_info where dossier_id= '"+sdlist.get(g)+"' and data_state='C')))");
ResultSet rs2 = stmt.executeQuery("select dfd.document_id,dfd.country_id,dfi.folder_name from dossier_folder_documents dfd,dossier_folder_info dfi where dfd.fk_dossier_folder_id=dfi.pk_dossier_folder_id and dfd.is_core is null and dfd.action='O' and dfd.fk_dossier_basic_info_id in (select pk_dossier_id from dossier_basic_info where dossier_id='"+vdlist.get(g)+"') and (dfd.document_id,dfi.folder_name) in (select dfd.document_id,dfi.folder_name from dossier_folder_documents dfd,dossier_folder_info dfi where dfd.fk_dossier_folder_id=dfi.pk_dossier_folder_id and dfd.fk_dossier_basic_info_id in (select pk_dossier_id from dossier_basic_info where dossier_id='"+sdlist.get(g)+"' and data_state='C'))");
ResultSetMetaData rsmd1 = rs1.getMetaData();
//ResultSetMetaData rsmd2 = rs2.getMetaData();
String temp5 = new String();
for(int f=1;f<=rsmd1.getColumnCount();f++)
{
data3+=rsmd1.getColumnName(f)+"/ /";}
temp4=data3;
data3="";
while(rs1.next())
{
System.out.println("In here...");
num2=g;
for(int x=1;x<=rsmd1.getColumnCount();x++)
{
temp5+=rs1.getString(x)+"/ /";
}
String data5 = new String();
data5=temp5;
sublist1.add(data5);
//System.out.println(sublist);
errvdlist.add(vdlist.get(num2));
errsdlist.add(sdlist.get(num2));
System.out.println("Validation Dossier ID for New Corruption: "+vdlist.get(num2));
System.out.println("Submission Dossier ID for New Corruption: "+sdlist.get(num2));
}
while(rs2.next() )
{
num2=g;
for(int x=1;x<=rsmd1.getColumnCount();x++)
{
temp6+=rs2.getString(x)+"/ /";
}
//String data6 = new String();
data6=temp6;
sublist2.add(data6);
//System.out.println(sublist);
errvdlist.add(vdlist.get(num2));
errsdlist.add(sdlist.get(num2));
System.out.println("Validation Dossier ID for Old: "+vdlist.get(num2));
System.out.println("Submission Dossier ID for Old: "+sdlist.get(num2));
}
}
我必须执行两个查询,并且使用了两个结果集:rs1和rs2。在我的输出中,执行了rs2的while循环,但未执行rs1。我最初以为用于rs1的查询存在问题,但事实并非如此。不会执行要打印“在这里...”的print语句,这意味着它甚至不会进入循环。有什么建议吗?
答案 0 :(得分:0)
一个ResultSet对象自动关闭,当生成它的Statement对象关闭,重新执行或用于从多个结果序列中检索下一个结果时。
因此,基本上,Statement
一次只能给您一个ResultSet
,因此在执行第二个查询时,您会丢失第一个结果。
使用两个Statement
实例可以使两个ResultSet
一起打开。