In this tutorials, we are going to understand the JDBC update program example. To do the update operations in JDBC, the API given us two different methods executeUpdate(String qry) and execute(String qry).

By using the any one of those two, we can do the JDBC update program in Java. Here is the difference between the Jdbc executeUpdate() and execute().

execueteUpdate() Example :

executepdate() method returns the integer value. The value represents that the number of rows effected in the database.

int rowsEffected = stmt.executepUpdate("update command");

execuete() Example :

execute() method returns boolean value. As we already discussed in the JDBC select example, we can use the execute() method for both select and non-select operations. If the resultant object contains ResultSet then the execute() method returns the true, it returns false if it is an update count or no records found.

boolean isResultSet = stmt.executep("update command");

Here is the simple example Jdbc Update program.

JDBC Update Program Example :
package com.onlinetutorialspoint.jdbc; 
import java.sql.Connection; 
import java.sql.DriverManager; 
import java.sql.Statement; 
public class Jdbc_Update_Example { 
    public static void main(String[] args) throws Exception { 
        Connection connection = null; 
        connection = DriverManager.getConnection( 
                "jdbc:mysql://localhost:3306/onlinetutorialspoint", "root", 
        Statement stmt = connection.createStatement(); 
        int count = stmt 
                .executeUpdate("update student set sname='rajesh' where sid=102"); 
        System.out.println(count + " Record(s) updated."); 


1 Record(s) updated.