Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollable ResultSet JDBC Postgresql

When I create a prepared statement like this in java (using JDBC):

pStmt = conn.prepareStatement(qry);

everything works ok. However when I want a scrollable resultset and use this:

pStmt = conn.prepareStatement(qry,ResultSet.TYPE_SCROLL_INSENSITIVE);

I get a syntax error:

org.postgresql.util.PSQLException: ERROR: syntax error at or near "RETURNING"

I'm not even using RETURNING in my query.

Any ideas?

Any help would be appreciated. Thanks

Update: It seems to work if I use this:

pStmt = db.prepareStatement(qry,ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

What is the difference between SENSITIVE and INSENSITIVE?

Thanks

like image 913
jtnire Avatar asked Nov 23 '10 18:11

jtnire


People also ask

Is ResultSet scrollable by default?

Now, as we have mentioned, we can scroll through records with the help of the ResultSet object. But, this ability does not come by default. The default behavior of the ResultSet object is that it is not updatable and the cursor it owns actually moves in one direction, forward only.

What is difference between scrollable and non scrollable ResultSet?

The main difference between scrollable and non scrollable cursors in DB2 is that scrollable cursors are used to move randomly through the result set while non-scrollable cursors are used to move sequentially forward through the result set.

How do you create a prepared Statement to support scrollable & read only ResultSet?

You can create a Statement that returns result sets in one of the following types: - TYPE_FORWARD_ONLY: the result set is not scrollable (default). - TYPE_SCROLL_INSENSITIVE: the result set is scrollable but not sensitive to database changes.


1 Answers

The second parameter to prepareStatement should be one of Statement.RETURN_GENERATED_KEYS or Statement.NO_GENERATED_KEYS.

I guess you want to use

PreparedStatement prepareStatement(String sql,
                                   int resultSetType,
                                   int resultSetConcurrency)
like image 133
Haderlump Avatar answered Oct 27 '22 23:10

Haderlump