对只中转结果集的无效操作: last
对只转发结果集的无效操作: last
程序中的一段代码如下:
Connection conn=null; Statement stmt=null; ResultSet rs=null; try{ conn=DriverManager.getConnection(url,user,password); stmt=conn.createStatement(); rs=stmt.executeQuery("select * from guestbook order by gst_time desc"); rs.last(); }catch(SQLException se){ se.printStackTrace(); } int rowCount=rs.getRow();
程序运行后,编译器报错如下:
javax.servlet.ServletException: 对只转发结果集的无效操作: last
java.sql.SQLException: 对只转发结果集的无效操作: last
解决方法:
使用带参数的方法来构造statement:
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY )
允许结果集移动,可以使用last()方法。