SQLSTATE 24000 - Invalid Cursor State(SQLSTATE 24000 - 游标状态无效)
问题描述
我连接到一个 DB2 数据库并进行以下查询.我不明白为什么会出现错误:无效的游标状态".
I connect to a DB2 database and makes the following query. I don't understand why I get the error: "invalid cursor state".
public static void blivPar() {
try {
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
stmt.setMaxRows(1000);
ResultSet drenge = stmt.executeQuery("SELECT * FROM People WHERE sex='M'");
ResultSet piger = stmt.executeQuery("SELECT * FROM People WHERE sex='F'");
drenge.first();
piger.first();
int i=0;
while(drenge.next()) {
while(piger.next()) {
i++;
System.out.print(i);
stmt.execute("INSERT INTO Couples Values ('"+drenge.getString(1) +
"','" + drenge.getString(2) +
"','" + piger.getString(1) +
"','" + piger.getString(2) + "')");
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
谢谢.
推荐答案
在 JDBC Javadocs 上找到了 Statement 接口的这个:用于执行静态 SQL 语句并返回它产生的结果的对象.
Found this on the JDBC Javadocs for the Statement interface: "The object used for executing a static SQL statement and returning the results it produces.
默认情况下,每个 Statement 对象只能同时打开一个 ResultSet 对象.因此,如果一个 ResultSet 对象的读取与另一个 ResultSet 对象的读取交错,则每个都必须由不同的 Statement 对象生成. Statement 接口中的所有执行方法都会隐式关闭一个 statment 的当前 ResultSet 对象,如果存在打开的对象."请参阅 声明 javadoc
By default, only one ResultSet object per Statement object can be open at the same time. Therefore, if the reading of one ResultSet object is interleaved with the reading of another, each must have been generated by different Statement objects. All execution methods in the Statement interface implicitly close a statment's current ResultSet object if an open one exists. " see Statement javadoc
所以在我看来,如果您希望同时打开两个结果集,您需要两个不同的语句.或者您需要完成第一个 ResultSet 的处理并关闭它,以便您可以重新使用 Statement 来创建第二个 ResultSet.
So it looks to me like you need two different Statements if you want two ResultSets open at the same time. Or you need to finish processing your first ResultSet and close it so you can re-use the Statement to create the second ResultSet.
这篇关于SQLSTATE 24000 - 游标状态无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLSTATE 24000 - 游标状态无效


基础教程推荐
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01