Example usage for javax.sql.rowset JdbcRowSet insertRow

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

Introduction

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

Prototype

void insertRow() throws SQLException;

Source Link

Document

Inserts the contents of the insert row into this ResultSet object and into the database.

Usage

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

/**
 * prepare and set columns value and inserts row
 *
 * @param load//  w ww  .  j a v a  2s.  com
 * @param row
 * @param jrs
 * @return
 */
protected boolean insertRow(Load load, Row row, JdbcRowSet jrs) {
    if (load == null || row == null || jrs == null) {
        return false;
    }
    try {
        jrs.moveToInsertRow();

        for (Column col : CollectionUtils.emptyIfNull(load.getColumns())) {
            if (col.getAuto()) {
                continue;
            }
            setColumnValue(load, row, col, jrs);
        }

        jrs.insertRow();
        // jrs.first(); TODO check the need of first() method
        return true;
    } catch (SQLException sqle) {
        Logger.warn("insertRow failed: " + sqle.getMessage());
        Logger.trace(sqle);
        return false;
    }
}

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

public void testJdbcRowSet() throws SQLException {

    JdbcRowSet jdbcRs = null;
    ResultSet rs = null;//from  ww  w.  j a  va2s .  com
    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);
    }
}