Java by API/javax.sql/RowSet

Материал из Java эксперт
Перейти к: навигация, поиск

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();
  }
}