JDBC Update Example | JDBC Update Query Example | executeUpdate()

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
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().
executepdate() method returns the integer value. The value represents that the number of rows effected in the database.
int rowsEffected = stmt.executepUpdate("update command");
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.
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; 
 
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
        connection = DriverManager.getConnection( 
                "jdbc:mysql://localhost:3306/onlinetutorialspoint", "root", 
                "123456"); 
 
        Statement stmt = connection.createStatement(); 
        int count = stmt 
                .executeUpdate("update student set sname='rajesh' where sid=102"); 
        System.out.println(count + " Record(s) updated."); 
 
    } 
 
}
Output:
1 Record(s) updated.

HQL update, delete Query Example
JDBC Select Program Example
JDBC Insert Program Example
JDBC Delete Program Example
JDBC PreparedStatement Example Program
Step by Step JDBC Program Example
Insert an Image using JDBC in Mysql DB
Read an Image in JDBC Example
CallableStatement in jdbc Example
ResultSetMetaData in JDBC Example
DatabaseMetaData in JDBC Example
Transaction Management in JDBC Example
Batch Processing in JDBC Example
JDBC Connection with Properties file
JDBC Scrollable ResultSet Example

HQL update, delete Query Example
JDBC Select Program Example
JDBC Insert Program Example
JDBC Delete Program Example
JDBC PreparedStatement Example Program
Step by Step JDBC Program Example
Insert an Image using JDBC in Mysql DB
Read an Image in JDBC Example
CallableStatement in jdbc Example
ResultSetMetaData in JDBC Example
DatabaseMetaData in JDBC Example
Transaction Management in JDBC Example
Batch Processing in JDBC Example
JDBC Connection with Properties file
JDBC Scrollable ResultSet Example
 


Δ
 JDBC Driver Types
 Step by Step JDBC Program
 JDBC Select Program
 JDBC Insert Program
 JDBC Update Program
 JDBC Delete Program
 JDBC Connection – Properties File
 JDBC PreparedStatement Program
 JDBC – CallableStatement Example
 JDBC – Read an Image from DB
 JDBC – Insert an Image in DB
 JDBC – Updatable ResultSet
 JDBC – Scrollable ResultSet
 JDBC – ResultSetMetaData
 JDBC – DatabaseMetaData
 JDBC – Transaction Management
 JDBC – Batch Processing
 JDBC Interview Questions