• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Invalid operation for read only resultset: updateFloat

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
https://coderanch.com/t/295932/JDBC/java/updateXXX-function-ResultSet
 
satish kumar
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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.
 
author & internet detective
Posts: 41936
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Satish,
Thanks for posting the solution!
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks nice post
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic