Connection con;
ResultSet rs;
ResultSet rsDetail;
Statement stat;
;
con = new Connection();
stat = con.createStatement();
rs = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rs.next())
{
info(rs.getString(1));
rsCredit = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rsCredit.next())
{
info( "第二次循环:"+rsCredit.getString(1));
}
}
ResultSet rs;
ResultSet rsDetail;
Statement stat;
;
con = new Connection();
stat = con.createStatement();
rs = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rs.next())
{
info(rs.getString(1));
rsCredit = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rsCredit.next())
{
info( "第二次循环:"+rsCredit.getString(1));
}
}
按照ADO.NET编程习惯,应该rs和rsCredit分别循环,对应rs中的每一条记录,输出一遍rsCredit中的记录 .
但实际情况是不管rs有多少条记录,第一个循环只会执行一次.看了Statement的帮助文档才知道,每个Statement对象只能对应一个ResultSet,在返回下一个ResultSet时会将上一个关掉,真是奇怪,执行一条语句就返回一个结果集,干吗非要把上一个关掉......
解决办法就是如果ResultSet要嵌套,则用两个Statement分别对应不同的ResultSet,有些bt.
Connection con;
ResultSet rs;
ResultSet rsDetail;
Statement stat;
Statement statCredit;
;
con = new Connection();
stat = con.createStatement();
statCredit = con.createStatement()
rs = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rs.next())
{
info(rs.getString(1));
rsCredit = statCredit .executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rsCredit.next())
{
info( "第二重循环:"+rsCredit.getString(1));
}
}
ResultSet rs;
ResultSet rsDetail;
Statement stat;
Statement statCredit;
;
con = new Connection();
stat = con.createStatement();
statCredit = con.createStatement()
rs = stat.executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rs.next())
{
info(rs.getString(1));
rsCredit = statCredit .executeQuery(strFmt("select * from basicdata.dbo.LedgerTable where dataAreaId = '%1'","ZB"));
while(rsCredit.next())
{
info( "第二重循环:"+rsCredit.getString(1));
}
}