Following is my code(Re-constructed) which select & update STATUS field depending upon the conditions. (Using Servlets, Oracle as Backend and JDBC driver)
ResultSet rs=null; String query = "select A.NAME, A.ADDRESS, A.STATUS, B.CLASS from TABLE_ONE A, TABLE_TWO B where A.STATUS='N'"; pstmt = con.prepareStatement(query,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE); rs = pstmt.executeQuery(); while(rs.next()) { String name = rs.getString("NAME"); String address = rs.getString("ADDRESS"); String class = rs.getString("CLASS"); String msg = //Other statements to check what status to be set if(msg.equals("OK")) rs.updateString("STATUS", "S"); else rs.updateString("STATUS", "E"); rs.updateRow(); }
I am getting the error while updating:
java.sql.SQLException: Invalid operation for read only resultset: updateString
Any suggestions will be appreciated.
Update 1: The same code was working when select statement was selecting data from single table, so is there any issue when selecting data from two tables in single query?
[Note: As @javaBeginner has mentioned in comments it will work only for one table.]
Advertisement
Answer
The following limitations are placed on queries for enhanced result sets. Failure to follow these guidelines will result in the JDBC driver choosing an alternative result set type or concurrency type.
To produce an updatable result set (from specification):
- A query can select from only a single table and cannot contain any join operations.
In addition, for inserts to be feasible, the query must select all non-nullable columns and all columns that do not have a default value. * A query cannot use “SELECT * “. (But see the workaround below.) * A query must select table columns only. It cannot select derived columns or aggregates such as the SUM or MAX of a set of columns.
To produce a scroll-sensitive result set:
- A query cannot use “SELECT * “. (But see the workaround below.)
- A query can select from only a single table.