Java Reference
In-Depth Information
when the
RowSet.updateRow()
method is called. A
RowSet
is made updatable by setting its
concurrency property to
ResultSet.CONCUR_UPDATABLE
. Once you have an updatable
RowSet
, you
can insert a new row, delete an existing row, or modify one or more column values.
Since requesting an updatable
RowSet
does not guarantee that you will actually get one, you should
check whether the
RowSet
is updatable by using
RowSet.getConcurrency()
.
Listing 18-3
illustrates
the use of the
rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE)
method to make a
RowSet
updatable and the use of
RowSet.getConcurrency()
to ensure that the
RowSet
actually is
updatable.
Listing 18-3: Making a RowSet updatable
package JavaDatabaseBible.ch18;
import java.sql.*;
import com.inet.tds.JDBCRowSet;
public class JDBCUpdatableRowSet{
public static void main(String[] argv){
String url = "jdbc:inetdae7:localhost:1433?database=LEDES";
String login = "jod";
String password = "jod";
try {
Class.forName("com.inet.tds.TdsDriver").newInstance();
JDBCRowSet rowSet = new JDBCRowSet();
//set url,login and password;
rowSet.setUrl( url );
rowSet.setUsername( login );
rowSet.setPassword( password );
//make the rowset scrollable and updatable
rowSet.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE);
//set the sql command
rowSet.setCommand(
"SELECT ID,FName,LName,EMail "+
"FROM CONTACTS WHERE FName = 'Ichabod'");
//execute the command
rowSet.execute();