Update record using Statement in Java

We saw how to Create a table and Insert Data using Statement in Java.

Now lets update the data into that is already present in the table using Statement.

Update record SQL

Below is the query that can be fired directly on database to update record.

Method from Statement Interface used

“Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.”

In case of Updating records, executeUpdate(String sql) returns the total number of records that where updated using the Update SQL statement.

Now lets see the sample code for firing this SQL using JDBC

Example : Update record using Statement in Java


Since we have JDK 7, we are using Try-with-resources Statement to handle the resources that are opened.


1. Statement executeUpdate()