首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-12-19 
对只转发结果集的无效操作: last程序中的一段代码如下:?Connection connnullStatement stmtnullResult

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


?

热点排行