Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import com.sun.rowset.CachedRowSetImpl;
- import com.sun.rowset.JdbcRowSetImpl;
- import com.sun.rowset.JoinRowSetImpl;
- import javax.sql.rowset.CachedRowSet;
- import javax.sql.rowset.JdbcRowSet;
- import javax.sql.rowset.JoinRowSet;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class TestJoinRowSet implements Runnable {
- private final String DB_URL = "jdbc:mysql://localhost/mysql";
- private final String DB_USER = "root";
- private final String DB_PASS = "";
- public static void main(String[] args) {
- new TestJoinRowSet().run();
- }
- public void run() {
- JoinRowSet jRowSet = null;
- // WebRowSet wRowSet = null;
- JdbcRowSet wRowSet = null;
- CachedRowSet cRowSet = null;
- try {
- wRowSet = new JdbcRowSetImpl();
- // wRowSet = new WebRowSetImpl();
- wRowSet.setUsername(DB_USER);
- wRowSet.setPassword(DB_PASS);
- wRowSet.setUrl(DB_URL);
- wRowSet.setCommand("SELECT host, user, password FROM user");
- wRowSet.setMatchColumn(new int[]{1,2});
- wRowSet.execute();
- cRowSet = new CachedRowSetImpl();
- cRowSet.setUsername(DB_USER);
- cRowSet.setPassword(DB_PASS);
- cRowSet.setUrl(DB_URL);
- cRowSet.setCommand("SELECT host, user, max_user_connections FROM user");
- cRowSet.setMatchColumn(new int[]{1,2});
- cRowSet.execute();
- jRowSet = new JoinRowSetImpl();
- jRowSet.addRowSet(wRowSet);
- jRowSet.addRowSet(cRowSet);
- showRows(jRowSet);
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (Exception e) {
- e.printStackTrace();
- } finally {
- try {
- jRowSet.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- }
- private void showRows(ResultSet set) throws SQLException {
- while (set.next()) {
- System.out.println(set.getString("host") + " " + set.getString("user") + "|" + set.getString("password") + "|" + set.getString("max_user_connections"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement