Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

JDBC Execute Update Example

JDBC Execute Update query is used to modify or return you an integer value specify the number of rows affected in the backend of database.


JDBC Video Tutorial: Create, Read, Update and Delete (CRUD) Operation examples JDBC Video tutorial - How to read Data from MySQL Database? JDBC Video tutorial - How to delete Data in a MySQL Database? Solving java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception JDBC Video tutorial - How to update Data in a MySQL Database? JDBC Video Tutorial- How to insert data into MySQL database table? JDBC Video Tutorial: How to download JDBC Driver for MySQL? JDBC Tutorial - Writing first JDBC example and running in Eclipse Java Cross Join MySQL Database Connectivity Example In Java Change Column Name in MySQL Java Mysql Connection Example JDBC ODBC Connection In Java ResultSet In Java Prepared Statement Example JdbcRowSet interface Java JdbcRowSet Example First Step towards JDBC! JDBC Training, Learn JDBC yourself Jdbc Get Column Names JDBC Example with MySQL JDBC Prepared Statement Update JDBC Prepared Statement Insert JDBC Prepared Statement Example JDBC Prepared statement Close JDBC Prepared Statement Addbatch JDBC Nested Resultset JDBC-Odbc Connection JDBC-Odbc Connectivity JDBC Insert Preparedstatement JDBC Insert Null JDBC Get Metadata JDBC Insert Record Jdbc Insert Statement JDBC Meta Data Get tables Jdbc Mysql Connection String Jdbc Mysql Connection Url JDBC Next Jdbc Get Connection JDBC Get Int JDBC Exception JDBC Get Row Count JDBC Functions JDBC Fetch JDBC Execute Update Example JDBC Execute Statement JDBC Execute Query JDBC Drive For Mysql JDBC Connectivity Code In Java JDBC connection timeout

JDBC Execute Update Example


JDBC Execute Update query is used to modify or return you an integer value specify the number of rows affected in the backend of  database.

The code illustrates a simple example from JDBC Execute update Example. In this Tutorial we want to describe you a code that helps you in understanding JDBC Execute update Example. For this we have a class JDBC Execute update, Inside this class we have a main method that include the list of following steps to be followed -

The first step is to import a package java.sql.* -The * specify the list of all the classes defined in this package that provides you an network interface for java front end application to communicate with backend database.

  Loading a driver is the next step to be followed by make a call to Class.forName( ) with driver class passed as argument.

  DriverManager.getConnection ( ) : This method return you a connection class object. This try to built a connection between Url and database.

   con.createStatement ( ) : This is used to return you Sql object. A connection object is used to send and execute sql query in the backend database.

   st.executeUpdate ( ) :  This method return you an integer value, this specify the number of rows to be affected in the table .

In case there is an exception in the try block, the subsequent catch block handle the exception and print it. On the execution of program, the code show you an updated item in the table.

import java.sql.*;

public class JdbcExecuteupdateExample {

  public static void main(String args[]) {

  Connection con = null;
  Statement st = null;

  String url = "jdbc:mysql://localhost:3306/";
  String db = "komal";
  String driver = "com.mysql.jdbc.Driver";
  String user = "root";
  String pass = "root";

  try {
  con = DriverManager.getConnection(url + db, user, pass);
  st = con.createStatement();

  String sql = "update person set cname='Rakesh' where id=4";

  System.out.println("Table updated.");

  catch (Exception e) {


Table updated.

Download code


Share on Google+Share on Google+

JDBC Execute Update Example

Posted on: November 17, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles



Discuss: JDBC Execute Update Example   View All Comments

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
December 23, 2011
not applicable

con.setAutoCommit(false); tis method is not necessary in tat program.. so ppl's pls ignore tat :)correct method is con.setAutoCommit(true);