Databases Reference
In-Depth Information
resultSetHoldability
While resultSetType defines the scrollability of the cursor, resultSetConcurrency
defines the updatabilty of the cursor. resultSetHoldability indicates that the result
set will remain open even after the statement is closed. The createStatement and
prepareStatement supporting all of these properties have the following syntax:
createStatement(int resultSetType, resultSetConcurrency,
resultSetHoldability)
prepareStatement(int resultSetType, resultSetConcurrency,
resultSetHoldability);
All three properties are optional. Example 5-10 defines a Statement object with a
scrollable and updatable ResultSet . It fetched the ResultSet row by row and
update the status whenever the record with value 5003 is found. It prints all the
records after the update is done.
Example 5-10 Scrollable and updatable Result set
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery("Select POID,Status from purchaseorder"
);
while(rs.next())
{
int id=rs.getInt(1);
String status = rs.getString(2);
if(id==5003 && status.toUpperCase().compareTo("UNSHIPPED")==0)
{
System.out.println("updating status to shipped for id value "+
id+".....");
rs.updateString(2,"Shipped");
rs.updateRow();
}
}
rs.beforeFirst();
System.out.println("Printing all the purchase order record status");
while(rs.next())
{
int id=rs.getInt(1);
String info = rs.getString(2);
System.out.println("id="+id+" info="+ info );
}
Search WWH ::




Custom Search