Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

a problem about read only ResultSet

 
Baijun Jiang
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have java codes like this:

String sql="select energy_etc.kwhexp from ...";
System.out.println(sql);
Statement kwhexp_stmt = conn.createStatement
(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet kwhexp_rs = kwhexp_stmt.executeQuery( sql);
double d=1.1;
while(kwhexp_rs.next()){
kwhexp_rs.updateDouble("kwhexp",d);
kwhexp_rs.updateRow();
d++;
}

When I execute these codes I got a error message:
Exception in thread "main" java.sql.SQLException: Invalid operation for read onl
y resultset: updateDouble
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:187)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:229)
at oracle.jdbc.driver.BaseResultSet.updateDouble(BaseResultSet.java:225)
at oracle.jdbc.driver.OracleResultSet.updateDouble(OracleResultSet.java:2816)
at MonthlyBillGeneration.main(MonthlyBillGeneration.java:34)


What could be the reason I cannot update my result set?
 
Ram Mohan
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't find anything wrong in your codes.
May some one help you.

Ram Mohan
 
Maximilian Xavier Stocker
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just because you asked for an updateable cursor doesn't mean you got one. The database is giving you a read only cursor for any/all of the following reasons:

- just not supported
- you haven't selected the tables primary key as part of your select
- the query has a joing
- the database doesn't support a cursor that is BOTH updatable and scrollable

If you add the primary key field to your query and it still doesn't work then you need to consult the documentation for your database as to when you get which type of cursor. Again not all cursor modes are supported by all databases in all circumstances. So there is something about your request that isn't supported and you'll have to find out what.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic