<%@ page language="java" import="java.util.*" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>显示所有学生页面</title>
</head>
<body>
<center>
<%
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433; DatabaseName=JSPTest";
//连接服务器和数据库
String userName = "sa"; //默认用户名
String userPwd = "123456"; //密码
Class.forName(driverName);
Connection Conn = DriverManager.getConnection(dbURL, userName, userPwd);
request.setCharacterEncoding("UTF-8");
String sql="select * from stu_info";
PreparedStatement pstmt=Conn.prepareStatement(sql);
ResultSet rs=pstmt.executeQuery();
Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Conn.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs.last();
%>你要查询的学生数据表中共有
<font size="5" color="red"><%=rs.getRow()%></font>人
<table border="2" bgcolor="ccceee" width="650">
<tr bgcolor="CCCCCC" align="center">
<td>记录条数</td><td>学号</td><td>姓名</td>
<td>性别</td><td>年龄</td><td>体重</td><td>身高</td>
</tr>
<% rs.beforeFirst();
while(rs.next()){%>
<tr align="center">
<td><%=rs.getRow()%></td>
<td><%=rs.getString("id") %></td>
<td><%=rs.getString("name") %></td>
<td><%=rs.getString("sex") %></td>
<td><%=rs.getString("age") %></td>
<td><%=rs.getString("weight") %></td>
<td><%=rs.getString("hight") %></td>
</tr>
<%} %>
</table>
</center>
<%if(pstmt!=null){pstmt.close();}
if(Conn!=null){Conn.close();}
%>
</body>
</html>
运行代码后,出现
javax.servlet.ServletException: com.microsoft.sqlserver.jdbc.SQLServerException: 只进结果集不支持请求的操作。
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
org.apache.jsp.find_005fstu_005f1_jsp._jspService(find_005fstu_005f1_jsp.java:198)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
好像是rs.last(),rs.beforeFirst()方法不能用。
原文:http://www.cnblogs.com/lls1350767625/p/7719673.html