SQLSTATE 24000 - Invalid cursor state

I connect to the DB2 database and make 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();
            }

        }

Thank.

+3
source share
1 answer

This was discovered in Javadocs JDBC for the Statement interface: "An object used to execute a static SQL statement and return the results it produces.

ResultSet Statement. , ResultSet , Statement. Statement ResultSet, , ". Statement javadoc

, , , ResultSets. ResultSet , Statement ResultSet.

+6

Source: https://habr.com/ru/post/1765127/


All Articles