7 个解决方案
#1
同时使用是你指向的游标位置不乱套了么?
为什么不用两个分别的ResultSet呢。。
为什么不用两个分别的ResultSet呢。。
#2
是两个分别的,resultset啊,代买如下ResultSet re = pr.executeQuery();
ResultSet re2=pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
他们应该是两个分别的实例对象啊
ResultSet re2=pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
他们应该是两个分别的实例对象啊
#3
在java里每个ResultSet结果集都需要一个单独的statement来支撑,如果想使用多个ResultSet就必须使用创建多个statement。
#4
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
re2.next();
上面这样写就没有错误
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
re2.next();
然后这样写,就会出现结果集关闭的错误
ResultSet re = pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
re2.next();
上面这样写就没有错误
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
re2.next();
然后这样写,就会出现结果集关闭的错误
#5
这样写,确定有错?我感觉没错!
#6
为什么先不封装好成两个对象然后直接取,jsp操作ResultSet 这是面向过程编程的思路吧,没有一点可重用性
#7
额,只是刚学jsp,先在jsp页面里面写写看,先在已经写在bean里面了,有可能是jsp页面的问题吧,谢谢各位的回答
#1
同时使用是你指向的游标位置不乱套了么?
为什么不用两个分别的ResultSet呢。。
为什么不用两个分别的ResultSet呢。。
#2
是两个分别的,resultset啊,代买如下ResultSet re = pr.executeQuery();
ResultSet re2=pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
他们应该是两个分别的实例对象啊
ResultSet re2=pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
他们应该是两个分别的实例对象啊
#3
在java里每个ResultSet结果集都需要一个单独的statement来支撑,如果想使用多个ResultSet就必须使用创建多个statement。
#4
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
re2.next();
上面这样写就没有错误
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
re2.next();
然后这样写,就会出现结果集关闭的错误
ResultSet re = pr.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
re2.next();
上面这样写就没有错误
PreparedStatement pr = con.prepareStatement("select * from onLine");
ResultSet re = pr.executeQuery();
PreparedStatement pr2 = con.prepareStatement("select * from onLine where name=?");
pr2.setString(1, (String) session.getAttribute("yongHu"));
ResultSet re2 = pr2.executeQuery();
int oL = 0;
for (; re.next();) {
if (1 == re.getInt("onLine")) {
oL++;
}
}
out.println("在线人数有:" + oL);
re2.next();
然后这样写,就会出现结果集关闭的错误
#5
这样写,确定有错?我感觉没错!
#6
为什么先不封装好成两个对象然后直接取,jsp操作ResultSet 这是面向过程编程的思路吧,没有一点可重用性
#7
额,只是刚学jsp,先在jsp页面里面写写看,先在已经写在bean里面了,有可能是jsp页面的问题吧,谢谢各位的回答