aspose file tools*
The moose likes JDBC and the fly likes a problem about read only ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "a problem about read only ResultSet" Watch "a problem about read only ResultSet" New topic
Author

a problem about read only ResultSet

Baijun Jiang
Greenhorn

Joined: Oct 13, 2005
Posts: 17
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?


SCEA, CISA.
Ram Mohan
Greenhorn

Joined: Oct 21, 2005
Posts: 26
I didn't find anything wrong in your codes.
May some one help you.

Ram Mohan
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: a problem about read only ResultSet