RowSet: setUrl(String url)
import javax.sql.rowset.CachedRowSet;
public class Main {
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();
while (rs.next()) {
if (rs.getInt("id") == 42) {
rs.setString(1, "newString");
rs.updateRow(); // Normal JDBC
rs.acceptChanges();
}
}
rs.close();
}
}
Related examples in the same category