Updating a Row in a Database Table Using an Updatable Result Set - Java JDBC

Java examples for JDBC:ResultSet

Description

Updating a Row in a Database Table Using 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 {
  public static void main(String[] args) throws Exception {
    try {//  w  ww .  j av a2  s  . c o  m
      Connection connection = null;

      Statement stmt = connection.createStatement(
          ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
      ResultSet resultSet = stmt.executeQuery("SELECT * FROM my_table");

      resultSet.first();

      resultSet.updateString("col_string", "new data");

      resultSet.updateRow();
    } catch (SQLException e) {
    }
  }
}

Related Tutorials