1 import java.sql.*;
2 import javax.sql.*;
3 import com.sun.rowset.*;
4
5 public class TestRowSetEvent {
6 public static void main(String[] args)
7 throws SQLException, ClassNotFoundException {
8
9 Class.forName("com.mysql.jdbc.Driver");
10 System.out.println("Driver loaded");
11
12
13 RowSet rowSet = new JdbcRowSetImpl();
14 rowSet.addRowSetListener(new RowSetListener() {
15 public void cursorMoved(RowSetEvent e) {
16 System.out.println("Cursor moved");
17 }
18
19 public void rowChanged(RowSetEvent e) {
20 System.out.println("Row changed");
21 }
22
23 public void rowSetChanged(RowSetEvent e) {
24 System.out.println("row set changed");
25 }
26 });
27
28
29 rowSet.setUrl("jdbc:mysql://localhost/javabook");
30 rowSet.setUsername("scott");
31 rowSet.setPassword("tiger");
32 rowSet.setCommand("select * from Student");
33 rowSet.execute();
34
35 rowSet.last();
36 rowSet.updateString("lastName", "Yao");
37 rowSet.updateRow();
38
39
40 rowSet.close();
41 }
42 }