Example usage for javax.sql.rowset JdbcRowSet execute

List of usage examples for javax.sql.rowset JdbcRowSet execute

Introduction

In this page you can find the example usage for javax.sql.rowset JdbcRowSet execute.

Prototype

void execute() throws SQLException;

Source Link

Document

Fills this RowSet object with data.

Usage

From source file:Test.java

public static void main(String[] args) throws Exception {
    String databaseUrl = "jdbc:derby://localhost:1527/contact";
    String username = "user";
    String password = "password";

    RowSetFactory rowSetFactory = null;
    rowSetFactory = RowSetProvider.newFactory("com.sun.rowset.RowSetFactoryImpl", null);
    JdbcRowSet rowSet = rowSetFactory.createJdbcRowSet();

    rowSet.setUrl(databaseUrl);//from   w  w w .ja  v a  2s  . c o m
    rowSet.setUsername(username);
    rowSet.setPassword(password);
    rowSet.setCommand("SELECT * FROM COLLEAGUES");
    rowSet.execute();

    while (rowSet.next()) {
        System.out.println(rowSet.getInt("ID") + " - " + rowSet.getString("FIRSTNAME"));
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar);");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')");

    JdbcRowSet jdbcRS = new JdbcRowSetImpl(conn);
    jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
    String sql = "SELECT * FROM survey";
    jdbcRS.setCommand(sql);//from   w ww. j  a  v a  2s  . c o m
    jdbcRS.execute();
    jdbcRS.addRowSetListener(new ExampleListener());

    while (jdbcRS.next()) {
        System.out.println("id=" + jdbcRS.getString(1));
        System.out.println("name=" + jdbcRS.getString(2));
    }
    conn.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getHSQLConnection();
    System.out.println("Got Connection.");
    Statement st = conn.createStatement();
    st.executeUpdate("create table survey (id int,name varchar);");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,'anotherValue')");

    JdbcRowSet jdbcRS;
    jdbcRS = new JdbcRowSetImpl(conn);
    jdbcRS.setType(ResultSet.TYPE_SCROLL_INSENSITIVE);
    String sql = "SELECT * FROM survey";
    jdbcRS.setCommand(sql);//from w  w w  .j a  v  a2 s .c  o m
    jdbcRS.execute();
    jdbcRS.addRowSetListener(new ExampleListener());

    while (jdbcRS.next()) {
        // each call to next, generates a cursorMoved event
        System.out.println("id=" + jdbcRS.getString(1));
        System.out.println("name=" + jdbcRS.getString(2));
    }
    conn.close();
}

From source file:com.kumarvv.setl.core.Loader.java

/**
 * check if row exists in target database
 *
 * @param load/*from   w  w  w  . j  av  a  2s. c om*/
 * @param row
 * @param jrs
 * @return
 * @throws SQLException
 */
protected boolean isRowExists(Load load, Row row, JdbcRowSet jrs) throws SQLException {
    if (load == null || row == null || jrs == null) {
        return false;
    }

    String sql = interpolator.interpolate(load.getSqlExists(), row.getData());

    jrs.setCommand(sql);
    jrs.execute();
    return jrs.next();
}

From source file:com.oracle.tutorial.jdbc.JdbcRowSetSample.java

public void testJdbcRowSet() throws SQLException {

    JdbcRowSet jdbcRs = null;
    ResultSet rs = null;//from w ww  . ja  v a  2  s.  co m
    Statement stmt = null;

    try {

        // An alternative way to create a JdbcRowSet object

        //      stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        //      rs = stmt.executeQuery("select * from COFFEES");
        //      jdbcRs = new JdbcRowSetImpl(rs);

        // Another way to create a JdbcRowSet object

        //      jdbcRs = new JdbcRowSetImpl();
        //      jdbcRs.setCommand("select * from COFFEES");
        //      jdbcRs.setUrl(this.settings.urlString);
        //      jdbcRs.setUsername(this.settings.userName);
        //      jdbcRs.setPassword(this.settings.password);
        //      jdbcRs.execute();

        jdbcRs = new JdbcRowSetImpl(con);
        jdbcRs.setCommand("select * from COFFEES");
        jdbcRs.execute();

        jdbcRs.absolute(3);
        jdbcRs.updateFloat("PRICE", 10.99f);
        jdbcRs.updateRow();

        System.out.println("\nAfter updating the third row:");
        CoffeesTable.viewTable(con);

        jdbcRs.moveToInsertRow();
        jdbcRs.updateString("COF_NAME", "HouseBlend");
        jdbcRs.updateInt("SUP_ID", 49);
        jdbcRs.updateFloat("PRICE", 7.99f);
        jdbcRs.updateInt("SALES", 0);
        jdbcRs.updateInt("TOTAL", 0);
        jdbcRs.insertRow();

        jdbcRs.moveToInsertRow();
        jdbcRs.updateString("COF_NAME", "HouseDecaf");
        jdbcRs.updateInt("SUP_ID", 49);
        jdbcRs.updateFloat("PRICE", 8.99f);
        jdbcRs.updateInt("SALES", 0);
        jdbcRs.updateInt("TOTAL", 0);
        jdbcRs.insertRow();

        System.out.println("\nAfter inserting two rows:");
        CoffeesTable.viewTable(con);

        jdbcRs.last();
        jdbcRs.deleteRow();

        System.out.println("\nAfter deleting last row:");
        CoffeesTable.viewTable(con);

    } catch (SQLException e) {
        JDBCTutorialUtilities.printSQLException(e);
    }

    finally {
        if (stmt != null)
            stmt.close();
        this.con.setAutoCommit(false);
    }
}