|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create aResultSetobject that is updatable. In order to do this, you supply theResultSetconstantCONCUR_UPDATABLEto thecreateStatementmethod, as you have seen in previous examples. TheStatementobject it creates will produce an updatableResultSetobject each time it executes a query. The following code fragment illustrates creating the updatableResultSetobjectuprs. Note that the code also makesuprsscrollable. An updatableResultSetobject does not necessarily have to be scrollable, but when you are making changes to a result set, you generally want to be able to move around in it. With a scrollable result set, you can move to rows you want to change, and if the type isTYPE_SCROLL_SENSITIVE, you can get the new value in a row after you have changed it.Connection con = DriverManager.getConnection("jdbc:mySubprotocol:mySubName"); Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet uprs = stmt.executeQuery("SELECT COF_NAME, PRICE FROM COFFEES");The
ResultSetobjectuprsmight look something like this:COF_NAME PRICE ------------------ ----- Colombian 7.99 French_Roast 8.99 Espresso 9.99 Colombian_Decaf 8.99 French_Roast_Decaf 9.99We can now use the new JDBC 2.0 methods in the
ResultSetinterface to insert a new row intouprs, delete an existing row fromuprs, or modify a column value inuprs.
|
|
Start of Tutorial > Start of Trail > Start of Lesson |
Search
Feedback Form |
Copyright 1995-2004 Sun Microsystems, Inc. All rights reserved.