rs.last() 给出仅前向结果集的无效操作:最后
我试图通过以下方式获取结果集的行数:
rs.last();
int row_count = rs.getRow();
但我收到 Invalid operation forforward only resultset : last
错误。结果集从 Oracle 10g 数据库获取数据。
这是我设置连接的方法:
Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionString = "jdbc:oracle:thin:@" + oracle_ip_address + ":" + oracle_db_port + ":" + oracle_db_sid;
Connection conn = DriverManager.getConnection(connectionString, oracle_db_username, oracle_db_password);
I am trying to get the row count of a result set by:
rs.last();
int row_count = rs.getRow();
but im getting an Invalid operation for forward only resultset : last
error. The result set is getting its data from an Oracle 10g database.
Here is how i set up my connection:
Class.forName("oracle.jdbc.driver.OracleDriver");
String connectionString = "jdbc:oracle:thin:@" + oracle_ip_address + ":" + oracle_db_port + ":" + oracle_db_sid;
Connection conn = DriverManager.getConnection(connectionString, oracle_db_username, oracle_db_password);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ResultSet.last()
和其他“绝对索引”查询操作仅在结果集可滚动时才可用;否则,您只能逐一迭代仅向前结果集。以下示例(来自javadocs)演示如何创建可滚动的
ResultSet
。请记住,使用可滚动查询会对性能产生影响。如果此特定
ResultSet
的目标只是获取其最后一个值,请考虑优化您的查询以仅返回该结果。ResultSet.last()
and other "absolutely-indexed" query operations are only available when the result set is scrollable; otherwise, you can only iterate one-by-one through the forward-only result set.The following example (from the javadocs) demonstrates how to create a scrollable
ResultSet
.Keep in mind that there are performance implications to using scrollable queries. If the goal of this particular
ResultSet
is only to grab its last value, please consider refining your query to return only that result.对于准备好的语句,您必须至少指定类型和并发模式,以便
last()
和isLast()
工作。For prepared statements, you must specify, at a minimum, both the type and the concurrency mode for
last()
andisLast()
to work.使用您的查询,而不是
SELECT * FROM name
。Instead of
SELECT * FROM names
use your query.