Java Reference
In-Depth Information
Table 18-2: ResultSet Upda te Methods
Data Type
Method
java.io.InputStream
updateAsciiStream(String columnName, InputStream x, int length)
java.io.InputStream
updateUnicodeStream(String columnName, InputStream x, int length)
java.io.InputStream
updateBinaryStream(String columnName, InputStream x, int length)
java.sql.Date
updateDate(String columnName, Date x)
java.sql.Time
updateTime(String columnName, Time x)
java.sql.Timestamp
updateTimestamp(String columnName, Timestamp x)
long
updateLong(String columnName, long x)
Object
updateObject(String columnName, Object x)
Object
updateObject(String columnName, Object x, int scale)
short
updateShort(String columnName, short x)
String
updateString(String columnName, String x)
NULL
updateNull(String columnName)
Caution
After updating a column value, you must call the updateRow() method to make a
permanent change in the database before moving the cursor, since changes made
using the update methods do not take effect until updateRow() is called. If you
move the cursor to another row before calling updateRow() , the updates will be
lost, and the row will revert to its previous column values.
Inserting a New Row
In addition to supporting updates, an updatable RowSet supports the insertion and deletion of entire
rows. The updatable RowSet object inherits from ResultSet the insert row , which is, in effect, a
dedicated row buffer in which you can build a new row.
The new row is created in a manner very similar to the row updates discussed earlier. The following
steps are involved:
1. Move the cursor to the insert row by calling the method moveToInsertRow() .
2. Set a new value for each column in the row using the appropriate update method.
3. Call the method insertRow to insert the new row into the ResultSet and, simultaneously, into
the database.
Listing 18-4 demonstrates the use of the updatable RowSet to insert a new row into a database.
Listing 18-4: Inserting a new row in an updatable RowSet
package JavaDatabaseBible.ch18;
import java.sql.*;
import com.inet.tds.JDBCRowSet;
public class JDBCUpdatableRowSetInsert{
public static void main(String[] argv){
Search WWH ::




Custom Search