Example usage for javax.sql.rowset JdbcRowSet deleteRow

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

Introduction

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

Prototype

void deleteRow() throws SQLException;

Source Link

Document

Deletes the current row from this ResultSet object and from the underlying database.

Usage

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

public void testJdbcRowSet() throws SQLException {

    JdbcRowSet jdbcRs = null;
    ResultSet rs = null;//  ww  w.  j a va  2s . 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);
    }
}