Databases Reference
In-Depth Information
The supported methods for the scrollable cursor are:
first()
last()
next()
previous()
absolute()
relative()
afterLast()
beforeLast()
Tip: Each ResultSet object is associated with a Statement,
PreparedStatement, or CallableStatement object. The sensitivity or the
updatability cannot be defined at the resultSet level. It should be defined while
creating the statement object itself, which means ResultSet objects created
for SQL statements using the same statement object will have the same
properties. So once the ResultSet object is created, it is not possible to
change the properties.
In the application getProducts , isCustomer uses the ResultSet object to fetch
the result of the query.
BatchUpdate
With batch updates, a group of updates can be done to the database at the same
time instead of updating one by one. The Statement object provides the following
methods for batch updates:
addBatch method can be used to add the SQL statements in the batch.
executeBatch method will execute all the batch statements at the same time.
executeBatch method will return the number of rows affected by the batch
update.
Example 5-11 shows how to do the batch updates using the Statement object.
Example 5-11 Batch update with Statement object
con.setAutoCommit(false);
Statement stmt=con.createStatement();
stmt.addBatch("create table cart(pid varchar(10), quantity int");
stmt.addBatch("insert into cart values('100-100-01',4)");
stmt.addBatch("insert into cart values('100-101-01',5)");
int[] numUpdates=stmt.executeBatch();
for(int i=0;i<numUpdates.length;i++)
{
if(numUpdates[i]==-2)
Search WWH ::




Custom Search