我的JBX不支持WHILE嵌套啊?!急死我了。(50分)

  • 主题发起人 主题发起人 Rick.Qin
  • 开始时间 开始时间
R

Rick.Qin

Unregistered / Unconfirmed
GUEST, unregistred user!
我这样写的WHILE的嵌套为啥第一层循环和第二层循环只执行一次啊??
String sql = "SELECT * FROM cdgl WHERE cdjb = 1";
ResultSet Rs = dbc.executeQuery(sql);
while (Rs.next()) {
out.print("<p>" + Rs.getInt("id") + ", " + Rs.getString("mlm") + "</p>");

String sql1 = "SELECT * FROM cdgl WHERE cdjb = 2";
ResultSet Rs1 = dbc.executeQuery(sql1);
while (Rs1.next()) {
out.print("<p>" + Rs1.getInt("id") + ", " + Rs1.getString("mlm") + "</p>");
/*
String sql2 = "SELECT * FROM cdgl WHERE cdjb = 3";
ResultSet Rs2 = dbc.executeQuery(sql2);
while (Rs2.next()) {
out.print("<p>" + Rs2.getInt("id") + ", " + Rs1.getString("mlm") + "</p>");
}
*/
}
}
 
那个注释符是应该去掉的,我再重新发一下。
String sql = "SELECT * FROM cdgl WHERE cdjb = 1";
ResultSet Rs = dbc.executeQuery(sql);
while (Rs.next()) {
out.print("<p>" + Rs.getInt("id") + ", " + Rs.getString("mlm") + "</p>");

String sql1 = "SELECT * FROM cdgl WHERE cdjb = 2";
ResultSet Rs1 = dbc.executeQuery(sql1);
while (Rs1.next()) {
out.print("<p>" + Rs1.getInt("id") + ", " + Rs1.getString("mlm") + "</p>");

String sql2 = "SELECT * FROM cdgl WHERE cdjb = 3";
ResultSet Rs2 = dbc.executeQuery(sql2);
while (Rs2.next()) {
out.print("<p>" + Rs2.getInt("id") + ", " + Rs1.getString("mlm") + "</p>");
}
}
}
 
当你执行同以个dbc在executeQuery的时候上个结果集自动就没有了。
所以根本循环不了,
可以先把一个结果集查询出来,并把所有结果存放到一个List里,
然后再在List里for循环,再进行查询。

 
是,这是ResultSet的缺陷,但是你说的并不是最好的解决办法。
 
后退
顶部