How to update a Row in a Database Table Using an updatable ResultSet

By | August 1, 2018

In previous post How to retrieve data from JDBC resultset in java we learnt how to read record/records from database using Read only ResultSet. In this post we will learn how to make a ResultSet updatable so that we can insert or update a record in database table.

Project structure in eclipse:

SQL Query to create employee_table and insert few rows in MySQL (jdbcdb schema)
(Note:Make sure you have created employee_table and inserted few records in jdbcdb database schema)
DB.sql 

After running above db script in your MySQL jdbcdb schema employee_table will have following content.

DBUtil.java class which is responsible to connect with MySQL database.

Model class Employee .java

Now let’s run our ClientTest.java class to update an email adress of an employee  whose employee id is 2.
You can modified this program as per your requirement.

After running ClientTest.java program you will look below  output on eclipse console:

Finally you have to query your database employee_table to see whether record is updated or not.

That’s all about  How to update a Row in a Database Table Using an updatable ResultSet

You May Also Like:

Calling StoredProcedure Using CallableStatement
Get ResultSet By Calling StoredProcedure Using CallableStatement
Calling database custom Function Using CallableStatement
JDBC batch update with Statement
JDBC batch update with PreparedStatement
JDBC batch update with CallableStatement
How to retrieve data from JDBC resultset in java
How to insert a Row in a Database Table Using an updatable ResultSet
JDBC ResultSet navigation methods example in java

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *