关于两次输出ResultSet结果的问题
原代码如下:
<label> 请选择待分析的用户A:
<select name= "userlist " onChange= "addphone(this); ">
<option> *未选择* </option>
<%
/********进行查询*********/
try {
Connection con = DriverManager.getConnection(url,user,password);
Statement smt = con.createStatement();
ResultSet rst = smt.executeQuery(sqlyuju);
while(rst.next()){
out.println( " <option value= ' " + rst.getString( "username ") + " '> " + rst.getString( "username ") + " </option> ");
}
%>
</select>
用户B:
<select name= "userlist2 " onChange= "addphone(this); ">
<option> *未选择* </option>
<%
rst.beforeFirst();
while(rst.next()){
out.println( " <option value= ' " + rst.getString( "username ") + " '> " + rst.getString( "username ") + " </option> ");
}
rst.close();
smt.close();
con.close();
} catch(
SQLException ex) {
out.println( "数据库连接查询错误 " + ex);
ex.printStackTrace();
}
%>
</select> </label>
为什么在第二个列表框中无法再次显示ResultSet的内容,用了beforeFirst()、first()、previous()都不行,应该怎么做才好啊。
------解决方案--------------------Statement smt = con.createStatement();
改成
Statement smt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
就可以了。