Example usage for javax.sql.rowset JdbcRowSet next

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

Introduction

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

Prototype

boolean next() throws SQLException;

Source Link

Document

Moves the cursor forward one row from its current position.

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 ww w.j  av a  2 s  .com*/
    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);/*  ww  w .ja  va 2  s . c om*/
    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);/*w  w w.  ja v  a  2 s  . co  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.Extractor.java

/**
 * parse data from jdbc row set//from  w w w.  j a  v a  2s .co  m
 *
 * @param jrs
 * @param meta
 * @return
 * @throws SQLException
 */
long parseData(JdbcRowSet jrs, ResultSetMetaData meta) throws SQLException {
    if (jrs == null || meta == null) {
        return 0;
    }

    long rowCount = 0;
    while (jrs.next()) {
        rowCount++;

        parseDataRow(jrs, meta);
        if (!isWithinLimit(rowCount)) {
            break;
        }
    }
    return rowCount;
}

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

/**
 * check if row exists in target database
 *
 * @param load// w w w.  j  a  v  a2 s .  c  o  m
 * @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();
}