Cancelling Updates to an Updatable Result Set - Java JDBC

Java examples for JDBC:ResultSet

Description

Cancelling Updates to an Updatable Result Set

Demo Code

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Main {
  void m() throws Exception {
    try {//from w  ww  . j ava 2  s  .c o  m
      Connection connection = null;
      // Create an updatable result set
      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();
    } catch (SQLException e) {
    }
  }
}

Related Tutorials