General discussion


Java/Oracle updatable ResultSet

By Kristin73 ·
I am trying to connect to an oracle database using jdbc, and then I create a statement and execute a SQL query. This works fine, and I get a resultset. The problem is, its seems like this resultset can't be updated!... Why?

Here's what i do, and the messages i get:

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

String url = "";

Connection conn = DriverManager.getConnection (url, "username", "password");

// Testing the Connection-object
System.out.println(" Connection closed? "+conn.isClosed());
System.out.println(" Connection readOnly? "+conn.isReadOnly());

// Find out if the DATABASE supports updatable resultsets:
DatabaseMetaData dmd = conn.getMetaData();

System.out.println(" Yes, the database supports updatable resultsets");
}else System.out.println(" The database does not support updatable resultsets!");

// Creating statement for updatable resultsets - with parameters Scroll_sensitive and Concur_updatable.

Statement stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE ResultSet.CONCUR_UPDATABLE);

//Creating resultset
ResultSet rs2 = stat.executeQuery("SELECT * from Database where id = 1");

// Test: Check out if rs2 is updatable!
System.out.println("-Resultset type:"+rs2.getStatement().getResultSetType());
System.out.println(" (Type_forward_only="+ResultSet.TYPE_FORWARD_ONLY
+", Type_scroll_insensitive="+ResultSet.TYPE_SCROLL_INSENSITIVE
+",Type_scroll_sensitive="+ResultSet.TYPE_SCROLL_SENSITIVE );

//Test concurrency:
int concurrency = rs2.getConcurrency();
if(concurrency==ResultSet.CONCUR_READ_ONLY) System.out.println(" Read Only");
else System.out.println(" NOT read only");
if(concurrency==ResultSet.CONCUR_UPDATABLE) System.out.println(" Updatable");
else System.out.println(" NOT updatable");

//Trying to update the value of the column "Name":

rs2.updateString("Name", "NN NNNN");// Does not work, because resultset is write protected! rs2.updateRow();
System.out.println("Row updated? " + rs2.rowUpdated());

}catch(SQLException e){System.out.println("Something went wrong during updating ! "+e);}


Results when i run this program:

Testing the Connection-object:
Connection closed? false
Connection readOnly? false

Testing the database:
Yes, the database supports updatable resultsets

Creating ResultSet
-Resultset type:1005
( Type_forward_only=1003, Type_scroll_insensitive=1004,Type_scroll_sensitive=1005 )

Read Only
NOT updatable

Exception: Something went wrong during updating! java.sql.SQLException: Not valid operation for write-protected resultset: updateString

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums