读书人

对只中转结果集的无效操作: last

发布时间: 2012-12-19 14:13:14 作者: rapoo

对只转发结果集的无效操作: 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()方法。


?

读书人网 >编程

热点推荐