Java by API/javax.sql/RowSet — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:22, 31 мая 2010
Содержание
RowSet: setCommand(String cmd)
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();
}
}
RowSet: setPassword(String password)
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();
}
}
RowSet: setString(int parameterIndex, String x)
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();
}
}
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();
}
}
RowSet: setUsername(String name)
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();
}
}