CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Updatable ResultSet in JDBC

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Updatable ResultSet in JDBC

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 ยท 3 min read ยท 0 Comments
Share: in X

Introduction

JDBC (Java Database Connectivity) is a popular API (Application Programming Interface) that allows Java programs to interact with databases. JDBC provides a set of classes and methods to access and manipulate data in a database. One of the important features of JDBC is the ability to update the result set. In this blog post, we will discuss the Updatable ResultSet example in JDBC.

What is UpdatableResultSet?

A result set is a set of rows that are returned from a database query. The Updatable ResultSet is a type of result set that allows us to update the data in the result set. In other words, we can modify the data in the result set and update the corresponding data in the database.

Example

Let’s consider a scenario where we have a table called “employees” in a database. This table contains the following columns: id, name, age, and salary. We want to update the salary of an employee based on their id. We can use the Updatable ResultSet to achieve this.

Following is an example code snippet that demonstrates how to use Updatable ResultSet:

import java.sql.*;

public class UpdatableResultSetDemo {
    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/mydatabase";
        String username = "root";
        String password = "password";

        Connection connection = DriverManager.getConnection(url, username, password);
        Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        ResultSet resultSet = statement.executeQuery("SELECT * FROM employees WHERE id = 1");

        if (resultSet.next()) {
            System.out.println("Employee Name: " + resultSet.getString("name"));
            System.out.println("Employee Age: " + resultSet.getInt("age"));
            System.out.println("Employee Salary: " + resultSet.getInt("salary"));

            resultSet.updateInt("salary", 50000);
            resultSet.updateRow();

            System.out.println("Employee Salary Updated Successfully");
        }

        resultSet.close();
        statement.close();
        connection.close();
    }
}

In this code, we first establish a connection to the database using the DriverManager class. We then create a statement object with the ResultSet.TYPE_SCROLL_SENSITIVE and ResultSet.CONCUR_UPDATABLE parameters. These parameters indicate that the result set is scrollable and updatable.

Next, we execute a SELECT query to retrieve the data for the employee with id 1. We use the next() method to move the cursor to the first row in the result set. We then print out the employee’s name, age, and salary using the getString() and getInt() methods.

After that, we update the employee’s salary to 50000 using the updateInt() method. We then call the updateRow() method to update the corresponding row in the database.

Finally, we close the result set, statement, and connection objects.

Conclusion

In this blog post, we discussed the Updatable ResultSet in JDBC and how it allows us to update data in the result set and correspondingly update the data in the database. We also provided an example code snippet that demonstrates how to use Updatable ResultSet in a Java program. By using Updatable ResultSet, we can easily update database records and improve the efficiency of our database interactions.

Related Posts:

  • Processing Results with ResultSet in JDBC
  • MySQL Commands for Developers
  • JDBC Interview Questions: Ace Your Technical Screening
  • Scrollable ResultSet in JDBC
  • Spring Data JPA Projection
  • Interface in Java: Mastering Abstraction and…
Tags:javajdbc
Was this article helpful?
โ† Previous ArticleScrollable ResultSet in JDBC
Next Article โ†’Thread Synchronization in Java

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap