JSP中关于statement.executeQuery(SQL)的问题,在线等
在java代码中有如下命令:StringT1=null;//T1是上个网页传进来的学号Stringurl=null;Connectionconn=null;Stateme...
在java代码中 有如下命令:
String T1=null;//T1是上个网页传进来的学号
String url = null;
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
url = "jdbc:oracle:thin:@localhost:1521:xe";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection(url, "system", "oracle");
statement = conn.createStatement();
T1 = request.getParameter("T1");
String sSql = "select * from stu where s#='" + T1+"'";
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));
到这里没有问题,下面:
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));//报错
是不是executeQuery()方法只能执行一次???为什么?该怎么解决? 展开
String T1=null;//T1是上个网页传进来的学号
String url = null;
Connection conn=null;
Statement statement=null;
ResultSet rs=null;
url = "jdbc:oracle:thin:@localhost:1521:xe";
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
conn = DriverManager.getConnection(url, "system", "oracle");
statement = conn.createStatement();
T1 = request.getParameter("T1");
String sSql = "select * from stu where s#='" + T1+"'";
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));
到这里没有问题,下面:
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));//报错
是不是executeQuery()方法只能执行一次???为什么?该怎么解决? 展开
3个回答
展开全部
要next一下,你这里只有一条记录直接调用rs.next();
String sSql = "select * from stu where s#='" + T1+"'";
rs = statement.executeQuery(sSql);
rs.next();
out.println(rs.getString(1));
到这里没有问题,下面:
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
rs.next();
out.println(rs.getString(1));//报错
String sSql = "select * from stu where s#='" + T1+"'";
rs = statement.executeQuery(sSql);
rs.next();
out.println(rs.getString(1));
到这里没有问题,下面:
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
rs.next();
out.println(rs.getString(1));//报错
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
By default, only one ResultSet object per Statement object can be open at the same time.
一个Statement只能打开一个resultSet,所以先把rs close掉 再executeQuery
一个Statement只能打开一个resultSet,所以先把rs close掉 再executeQuery
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
rs.close();
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));
使用s.close(),把前面那个结果集给关闭~
sSql = "select * from quarterInfo where s# ='"+ T1+"'";//查询住宿信息
rs = statement.executeQuery(sSql);
out.println(rs.getString(1));
使用s.close(),把前面那个结果集给关闭~
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询