开发者

SQLSTATE 24000 - Invalid Cursor State

开发者 https://www.devze.com 2023-01-16 16:11 出处:网络
I connect to a DB2 database and makes the following query. I don\'t understand why I get the error: \"invalid cursor state\".

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'");
                R开发者_StackOverflow中文版esultSet 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();
            }

        }

Thank you.


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.

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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消