Example usage for javax.sql.rowset JdbcRowSet updateRow

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

Introduction

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

Prototype

void updateRow() throws SQLException;

Source Link

Document

Updates the underlying database with the new contents of the current row of this ResultSet object.

Usage

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

/**
 * prepares and sets columns value and updates row
 * //from   w w w.  j  av a2s.  c o  m
 * @param load
 * @param row
 * @param jrs
 * @return
 */
protected boolean updateRow(Load load, Row row, JdbcRowSet jrs) {
    if (load == null || row == null || jrs == null) {
        return false;
    }
    try {
        for (Column col : CollectionUtils.emptyIfNull(load.getColumns())) {
            if (col.getAuto() || col.getNk() || !col.isUpdate() || isNotEmpty(col.getGenerator())) {
                continue;
            }
            setColumnValue(load, row, col, jrs);
        }

        jrs.updateRow();
        return true;
    } catch (SQLException e) {
        Logger.warn("updateRow failed: " + e.getMessage());
        Logger.trace(e);
        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  .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);
    }
}