List of usage examples for javax.sql.rowset CachedRowSet acceptChanges
public void acceptChanges() throws SyncProviderException;
CachedRowSet
object to the underlying data source. From source file:Main.java
public static void main(String[] args) throws Exception { CachedRowSet rs; String ROWSET_IMPL_CLASS = "com.sun.rowset.CachedRowSetImpl"; Class c = Class.forName(ROWSET_IMPL_CLASS); rs = (CachedRowSet) c.newInstance(); rs.setUrl("jdbc:postgresql:dbname"); rs.setUsername("username"); rs.setPassword("password"); rs.setCommand("select * from members where name like ?"); rs.setString(1, "I%"); rs.execute();//from ww w. j av a 2 s.c o m while (rs.next()) { if (rs.getInt("id") == 42) { rs.setString(1, "newString"); rs.updateRow(); // Normal JDBC rs.acceptChanges(); } } rs.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { CachedRowSet rs; // Create the class with class.forName to avoid importing // from the unsupported com.sun packages. Class c = Class.forName(ROWSET_IMPL_CLASS); rs = (CachedRowSet) c.newInstance(); rs.setUrl("jdbc:postgresql:tmclub"); rs.setUsername("ian"); rs.setPassword("secret"); rs.setCommand("select * from members where name like ?"); rs.setString(1, "I%"); // This will cause the RowSet to connect, fetch its data, and // disconnect rs.execute();//from w w w . j a v a 2s . c om // Some time later, the client tries to do something. // Suppose we want to update data: while (rs.next()) { if (rs.getInt("id") == 42) { rs.setString(1, "Marvin"); rs.updateRow(); // Normal JDBC // This additional call tells the CachedRowSet to connect // to its database and send the updated data back. rs.acceptChanges(); } } // If we're all done... rs.close(); }