Advertisement
tnngo2

APJ 2 - Session 3 - CachedRowSet

Mar 15th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import com.sun.rowset.*;
  2. import java.sql.*;
  3. import javax.sql.rowset.CachedRowSet;
  4. import javax.sql.rowset.JdbcRowSet;
  5.  
  6. /**
  7.  *
  8.  * @author tnngo2
  9.  */
  10. public class CachedRowSetDemo {
  11.     Connection cn;
  12.  
  13.    
  14.     public static void main(String[] args) throws ClassNotFoundException, SQLException{
  15.            
  16.             CachedRowSet rowSet = new CachedRowSetImpl();
  17.                    
  18.             rowSet.setUrl("jdbc:sqlserver://localhost;DatabaseName=DeveloperApps");
  19.             rowSet.setUsername("sa");
  20.             rowSet.setPassword("123456");
  21.  
  22.             rowSet.setCommand("SELECT * FROM ToppingDetails");
  23.            
  24.             int[] keys = {1};
  25.             rowSet.setKeyColumns(keys);
  26.             rowSet.execute();
  27.  
  28.             while (rowSet.next()) {
  29.                 System.out.println(rowSet.getString(1) + " " + rowSet.getString(2));
  30.             }
  31.            
  32.             rowSet.close();
  33.            
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement