When you create a Statement
(or PreparedStatement
), you need to specify the result set type, if you don't the driver will use the default (TYPE_FORWARD_ONLY
).
So to get a scrollable ResultSet
, you need to use
PreparedStatement ps = connection.prepareStatement(query,
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
See the javadoc of Connection.prepareStatement(sql, resultSetType, resultSetConcurrency)
.
Also be aware that your current code is leaking resources. You are creating a PreparedStatement
in a method and never closing it. You might want to restructure your code so you can close both the statement and the result set in the same place. Closing the statement in its current place won't work, as that would also close the ResultSet
before you can use it.
Disclosure: I am a developer of the Jaybird JDBC driver.