Java Reference
In-Depth Information
A RowSetEvent is generated when something significant happens in a RowSet , such as a change in a
column value. Being JavaBeans, RowSets can use the Java event model to notify listeners when the
RowSet is changed.
These are the RowSetListener methods:
 
rowSetChanged — Called when the rowset is changed, for example, when a SQL command is
executed
 
rowChanged — Called when a row is inserted, updated, or deleted
 
cursorMoved — Called when a rowset's cursor is moved
The example of Listing 18-5 illustrates the use of RowSet events to monitor changes to a RowSet . In
this example, a RowSetListener is used to report the insertion of a new row in the Contacts Table.
Note the use of the method RowSet.moveToCurrentRow() in the RowSetListener . This method is
used to return to the current row when the cursor is on the insertRow . This allows the
RowSetListener to report the contents of the row just added.
Listing 18-5: Using RowSet events
package JavaDatabaseBible.ch18;
import java.sql.*;
import javax.sql.*;
import com.inet.tds.JDBCRowSet;
public class JDBCUpdatableRowSetInsert{
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);
// add a RowSetListener
rowSet.addRowSetListener(new RowSetChangeListener());
Search WWH ::




Custom Search