Advertisement
Guest User

Untitled

a guest
Sep 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1. package test;
  2.  
  3. import com.sun.rowset.CachedRowSetImpl;
  4. import com.sun.rowset.JdbcRowSetImpl;
  5. import com.sun.rowset.JoinRowSetImpl;
  6.  
  7. import javax.sql.rowset.CachedRowSet;
  8. import javax.sql.rowset.JdbcRowSet;
  9. import javax.sql.rowset.JoinRowSet;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12.  
  13. public class TestJoinRowSet implements Runnable {
  14.     private final String DB_URL  = "jdbc:mysql://localhost/mysql";
  15.     private final String DB_USER = "root";
  16.     private final String DB_PASS = "";
  17.  
  18.     public static void main(String[] args) {
  19.         new TestJoinRowSet().run();
  20.     }
  21.  
  22.     public void run() {
  23.         JoinRowSet jRowSet = null;
  24.  
  25. //        WebRowSet wRowSet = null;
  26.         JdbcRowSet wRowSet = null;
  27.         CachedRowSet cRowSet = null;
  28.         try {
  29.             wRowSet = new JdbcRowSetImpl();
  30. //            wRowSet = new WebRowSetImpl();
  31.             wRowSet.setUsername(DB_USER);
  32.             wRowSet.setPassword(DB_PASS);
  33.             wRowSet.setUrl(DB_URL);
  34.             wRowSet.setCommand("SELECT host, user, password FROM user");
  35.             wRowSet.setMatchColumn(new int[]{1,2});
  36.             wRowSet.execute();
  37.  
  38.             cRowSet = new CachedRowSetImpl();
  39.             cRowSet.setUsername(DB_USER);
  40.             cRowSet.setPassword(DB_PASS);
  41.             cRowSet.setUrl(DB_URL);
  42.             cRowSet.setCommand("SELECT host, user, max_user_connections FROM user");
  43.             cRowSet.setMatchColumn(new int[]{1,2});
  44.             cRowSet.execute();
  45.  
  46.             jRowSet = new JoinRowSetImpl();
  47.  
  48.             jRowSet.addRowSet(wRowSet);
  49.             jRowSet.addRowSet(cRowSet);
  50.  
  51.             showRows(jRowSet);
  52.         } catch (SQLException e) {
  53.             e.printStackTrace();
  54.         } catch (Exception e) {
  55.             e.printStackTrace();
  56.         } finally {
  57.             try {
  58.                 jRowSet.close();
  59.             } catch (SQLException e) {
  60.                 e.printStackTrace();
  61.             }
  62.         }
  63.     }
  64.  
  65.     private void showRows(ResultSet set) throws SQLException {
  66.         while (set.next()) {
  67.             System.out.println(set.getString("host") + " " + set.getString("user") + "|" + set.getString("password") + "|"  + set.getString("max_user_connections"));
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement