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 aResultSet
object that is updatable. In order to do this, you supply theResultSet
constantCONCUR_UPDATABLE
to thecreateStatement
method, as you have seen in previous examples. TheStatement
object it creates will produce an updatableResultSet
object each time it executes a query. The following code fragment illustrates creating the updatableResultSet
objectuprs
. Note that the code also makesuprs
scrollable. An updatableResultSet
object 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
ResultSet
objectuprs
might 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
ResultSet
interface 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-2005 Sun Microsystems, Inc. All rights reserved.