Example usage for java.sql ResultSet cancelRowUpdates

List of usage examples for java.sql ResultSet cancelRowUpdates

Introduction

In this page you can find the example usage for java.sql ResultSet cancelRowUpdates.

Prototype

void cancelRowUpdates() throws SQLException;

Source Link

Document

Cancels the updates made to the current row in this ResultSet object.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Connection conn = getConnection();
    Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

    st.executeUpdate("create table survey (id int,name varchar(30));");
    st.executeUpdate("insert into survey (id,name ) values (1,'nameValue')");
    st.executeUpdate("insert into survey (id,name ) values (2,null)");
    st.executeUpdate("insert into survey (id,name ) values (3,'Tom')");

    ResultSet rs = st.executeQuery("SELECT * FROM survey");

    // Move cursor to the row to update
    rs.first();/*w  w  w  .j a  v a2s .c  o  m*/

    // Update the value of column column_1 on that row
    rs.updateString("name", "new data");

    // Discard the update to the row
    rs.cancelRowUpdates();

    rs.close();
    st.close();
    conn.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String driverName = "com.jnetdirect.jsql.JSQLDriver";
    Class.forName(driverName);//from   www  .j  a  v  a2  s . c  o m

    String serverName = "127.0.0.1";
    String portNumber = "1433";
    String mydatabase = serverName + ":" + portNumber;
    String url = "jdbc:JSQLConnect://" + mydatabase;
    String username = "username";
    String password = "password";

    Connection connection = DriverManager.getConnection(url, username, password);
    Statement stmt = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");

    // Move cursor to the row to update
    resultSet.first();

    // Update the value of column col_string on that row
    resultSet.updateString("col_string", "new data");

    // Discard the update to the row
    resultSet.cancelRowUpdates();

}

From source file:com.github.woonsan.jdbc.jcr.impl.JcrJdbcResultSetTest.java

@Test
public void testUnsupportedOperations() throws Exception {
    Statement statement = getConnection().createStatement();
    ResultSet rs = statement.executeQuery(SQL_EMPS);

    try {/*from ww w . j a va  2s.  c  om*/
        rs.getWarnings();
        fail();
    } catch (UnsupportedOperationException ignore) {
    }

    try {
        rs.clearWarnings();
        fail();
    } catch (UnsupportedOperationException ignore) {
    }

    try {
        rs.getCursorName();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("ename");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.isLast();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.beforeFirst();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.afterLast();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.first();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.last();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.absolute(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.relative(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.previous();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.moveToCurrentRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNull(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNull("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBoolean(1, true);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBoolean("col1", true);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateByte(1, (byte) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateByte("col1", (byte) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateShort(1, (short) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateShort("col1", (short) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateInt(1, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateInt("col1", 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateLong(1, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateLong("col1", (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateFloat(1, (float) 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateFloat("col1", (float) 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDouble(1, 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDouble("col1", 0.1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBigDecimal(1, new BigDecimal("100000000"));
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBigDecimal("col1", new BigDecimal("100000000"));
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateString(1, "Unknown");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateString("col1", "Unknown");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBytes(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBytes("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDate(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateDate("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTime(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTime("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTimestamp(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateTimestamp("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject(1, null, 1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject("col1", null, 1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateObject("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.insertRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.deleteRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.refreshRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.cancelRowUpdates();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.moveToInsertRow();
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1, (Map<String, Class<?>>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("col1", (Map<String, Class<?>>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRef(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRef("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getBlob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getBlob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getClob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getClob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getURL(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getURL("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRef(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRef("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, (Blob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", (Blob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, (Clob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", (Clob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateArray(1, (Array) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateArray("col1", (Array) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRowId(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getRowId("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRowId(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateRowId("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNString(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNString("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, (NClob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", (NClob) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNClob(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNClob("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getSQLXML(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getSQLXML("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateSQLXML(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateSQLXML("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNString(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNString("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNCharacterStream(1);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getNCharacterStream("col1");
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null, (long) 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", null, 0);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateAsciiStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBinaryStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream(1, null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateCharacterStream("col1", null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob(1, (InputStream) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateBlob("col1", (InputStream) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob(1, (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateClob("col1", (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob(1, (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.updateNClob("col1", (Reader) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject(1, (Class<?>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    try {
        rs.getObject("col1", (Class<?>) null);
        fail();
    } catch (SQLFeatureNotSupportedException ignore) {
    }

    rs.close();
    assertTrue(rs.isClosed());

    statement.close();
    assertTrue(statement.isClosed());
}