wood burning stoves 2.0*
The moose likes JDBC and the fly likes Invalid operation for read only resultset: updateFloat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Invalid operation for read only resultset: updateFloat" Watch "Invalid operation for read only resultset: updateFloat" New topic
Author

Invalid operation for read only resultset: updateFloat

satish kumar
Greenhorn

Joined: Nov 26, 2004
Posts: 18
When I run the code below, I am getting exception "Invalid operation for read only resultset: updateFloat" although I am using updatable resultset. Any idea what's causing this? [I am using jdk1.5.0. However, Oracle jdbc driver I am using is meant for jdk1.4]

...Code Snippet ...
Statement stmt = tOra3.myConn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet srs = stmt.executeQuery("SELECT * FROM EMP");
while(srs.next()) {
if (srs.getString("ENAME").equalsIgnoreCase("SATISH")) {
srs.updateFloat("ENAME",10000);
srs.updateRow();
tOra3.myConn.commit();
break;
}
}

....Complete Code...
import java.sql.*;
public class TestOracle3 {
Connection myConn= null;
/** Creates a new instance of TestOracle3 */
public TestOracle3() {
try {
Class.forName("oracle.jdbc.OracleDriver");
myConn = DriverManager.getConnection(
"jdbc racle:thin:@sattiku:1521:satish",
"scott",
"tiger");
myConn.setAutoCommit(false);
} catch(ClassNotFoundException cnfe) {
System.out.println(cnfe.getMessage());
} catch(SQLException sqle) {
System.out.println(sqle.getMessage());
}
}

public static void main(String[] args) {
TestOracle3 tOra3 = new TestOracle3();
try {
Statement stmt = tOra3.myConn.createStatement(
ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet srs = stmt.executeQuery("SELECT * FROM EMP");
while(srs.next()) {
if (srs.getString("ENAME").equalsIgnoreCase("SATISH")) {
srs.updateFloat("ENAME",10000);
srs.updateRow();
tOra3.myConn.commit();
break;
}
}
srs.close();
tOra3.myConn.close();
} catch(SQLException sqle) {
System.out.println("SQL Exception: " + sqle.getMessage());
}
}

}
satish kumar
Greenhorn

Joined: Nov 26, 2004
Posts: 18
I found the answer by searching earlier discussions in the forum. (I should remember to search before I ask)

Select * makes the resultset readonly. Select COLUMNNAME makses it updatable
http://www.coderanch.com/t/295932/JDBC/java/updateXXX-function-ResultSet
satish kumar
Greenhorn

Joined: Nov 26, 2004
Posts: 18
(more info from Oracle jdbc developer guide)

Result Set Limitations

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:

* 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.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30789
    
157

Satish,
Thanks for posting the solution!


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
jitendra vishnoi
Greenhorn

Joined: Jan 19, 2010
Posts: 10
Thanks nice post
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Invalid operation for read only resultset: updateFloat