java.sql.SQLException: 对只转发结果集的无效操作: last
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:145)
at oracle.jdbc.driver.BaseResultSet.last(BaseResultSet.java:81)
at com.ambow.upgrade.comm.UpGradeService.deleteOpr(UpGradeService.java:568)
at com.ambow.upgrade.comm.UpGradeService.loadData(UpGradeService.java:126)
at com.ambow.upgrade.comm.UpGradeService.exeUpgrade(UpGradeService.java:519)
at com.ambow.upgrade.comm.UpGradeService.main(UpGradeService.java:528)
JAVA代码:
pstmt = sourceConn.prepareStatement(findSql);
pstmt.executeUpdate();
rs = pstmt.executeQuery();
rs.last();//移到最后一行 出错代码行
int rowCount = rs.getRow(); //得到当前行号,也就是记录数
rs.beforeFirst(); //还要用到记录集,就把指针再移到初始化的位置
出错原因见这里:
http://www.cnblogs.com/mingal/archive/2007/03/07/666373.html
因为初学,所以,在建立Statement时使用默认参数。导致在使用执行rs.last()时,产生“java.sql.SQLException:对只转发结果集的无效操作:last”的异常。
最后在建立Statement时加入相关参数,就可以解决了。
操作查询结果集的过程中出现异常
出现异常的语句: rs.last();
异常的详细信息:对只转发结果集的无效操作: last
解决办法: stat = conn.createStatement();
改为 stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY); 就可以了
分析: 异常出现于移动结果集的指针时,原因是在生成statement对象的时候提供的参数不同
无参数的那个方法使用的是默认参数,statement执行后得到的结果集类型为 ResultSet.TYPE_FORWARD_ONLY.这种类型的结果集只能通过rs.next();方法逐条读取,使用其他方法就会报异常. 如果想执行一些复杂的移动结果集指针的操作就要使用其他参数了
顺便简单介绍一下各个参数:
ResultSet.TYPE_FORWARD_ONLY (略)
ResultSet.TYPE_SCROLL_INSENSITIVE 双向滚动,但不及时更新,就是如果数据库里的数据修改过,并不在ResultSet中反应出来。
ResultSet.TYPE_SCROLL_SENSITIVE 双向滚动,并及时跟踪数据库里的更新,以便更改ResultSet中的数据。
ResultSet.CONCUR_READ_ONLY 只读取ResultSet
ResultSet.CONCUR_UPDATABLE 用ResultSet更新数据库
修改后的代码:
pstmt = sourceConn.prepareStatement(findSql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pstmt.executeUpdate();
rs = pstmt.executeQuery();
rs.last();//移到最后一行
int rowCount = rs.getRow(); //得到当前行号,也就是记录数
rs.beforeFirst(); //还要用到记录集,就把指针再移到初始化的位置
分享到:
相关推荐
java.sql.SQLException: 不支持的字符集 (在类路径中添加 orai18n.jar): ZHS16GBK ……
NULL 博文链接:https://listen-raining.iteye.com/blog/1962065
在oracle里面运行一下,解决Exception java.sql.SQLException ORA-00600 内部错误代码
服务器出现java.sql.SQLException No suitable driver found for 的
NULL 博文链接:https://zhang-zling.iteye.com/blog/980488
oracle ora-各种常见java.sql.SQLException归纳
java.sql.SQLException: null, message from server: “Host ‘223.72.41.7’ is not allowed to connect to this MySQL server” 客户端访问时报错: 解决方法: 1,登陆服务器 mysql> use mysql; //用mysql ...
本文主要介绍了关于MySQL存储表情报错:java.sql.SQLException: Incorrect string value: ‘\xF0\x9F\x92\xA9\x0D\x0A…’的相关解决方法,分享出供大家参考学习,下面话不多说了,来一起看看详细的介绍: ...
oracle 10g 数据库驱动下载:oracle jdbc dirver
主要给大家介绍了关于MySQL存储表情时报错:java.sql.SQLException: Incorrect string value: 'xF0x9Fx92xA9x0Dx0A...'的解决方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。
Q: I am working with ... I am using updateBinaryStream method of resultset to update the BLOB field but it is failing after giving following exception java.sql.SQLException: Internal Error: Unable to
mysql5.6连接驱动jaf,可处理报错java.sql.SQLException: No suitable driver
java.sql.SQLException: Operation not allowed after ResultSet closed java.sql.SQLException: QueryRunner requires a DataSource to be invoked in this way, or a Connection should be passed in
异常错误:java.sql.SQLException: The server time zone value ‘?й???’ is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTime...
该用户与可信 SQL Server 连接无关联。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient....
问题是这样的…我在VS2008直接运行打开网页,可以连接... 异常详细信息: System.Data.SqlClient.SqlException: 无法打开登录所请求的数据库 “TakeClass”。登录失败。 用户 ‘2D2727E2578F446\ASPNET’ 登录失败。
绝对好用的9i驱动包+10g驱动包 解决java.sql.SQLException: 不支持的特性 解决oracle.jdbc.driver.OracleDatabaseMetaData.supportsGetGeneratedKeys()Z异常 等等
Caused by: java.sql.SQLException: java.lang.ClassNotFoundException: org.apache.hive.jdbc.HiveDriver at com.trs.gateway.commons.hive.HiveFeature.getConnection(HiveFeature.java:57) at ...
import java.sql.SQLException; import java.sql.Statement; import java.sql.ResultSet; /** * @author Administrator * */ public class sqlServer { String DBDriver=...