You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to JDBC specifications, invoking beforeFirst() on a TYPE_FORWARD_ONLY ResultSet should either throw a SQLException or have no effect, as TYPE_FORWARD_ONLY ResultSets do not support cursor movements other than forward.
In the provided test case, a ResultSet is created with TYPE_FORWARD_ONLY and CONCUR_READ_ONLY parameters. After iterating through the ResultSet using rs.next(), an attempt is made to reset the cursor to the beginning of the ResultSet using rs.beforeFirst(). Contrary to expectations, this operation does not throw an error and appears to succeed.
@Testpublicvoidtest() {
try (Connectioncon = DriverManager.getConnection("jdbc:pgsql://localhost:5432/test13?user=user&password=password")) {
Statementstmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
stmt.execute("CREATE TABLE table13_0 (id INT PRIMARY KEY, name VARCHAR(20))");
stmt.execute("INSERT INTO table13_0 VALUES (1, 'name1'), (2, 'name2'), (3, 'name3')");
ResultSetrs = stmt.executeQuery("SELECT * FROM table13_0");
while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
rs.beforeFirst(); // expected throw error for ResultSet.TYPE_FORWARD_ONLYwhile (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2));
}
} catch (SQLExceptione) {
System.out.println(e.getMessage());
}
}
The text was updated successfully, but these errors were encountered:
According to JDBC specifications, invoking beforeFirst() on a TYPE_FORWARD_ONLY ResultSet should either throw a SQLException or have no effect, as TYPE_FORWARD_ONLY ResultSets do not support cursor movements other than forward.
In the provided test case, a ResultSet is created with TYPE_FORWARD_ONLY and CONCUR_READ_ONLY parameters. After iterating through the ResultSet using rs.next(), an attempt is made to reset the cursor to the beginning of the ResultSet using rs.beforeFirst(). Contrary to expectations, this operation does not throw an error and appears to succeed.
The text was updated successfully, but these errors were encountered: