Insert Update Delete Record JDBC

Infact, without closing Connection object, any number of operations can be performed on the database. Here, three operations, Insert Update Delete Record JDBC are performed in a single program.

You have seen earlier inserting record, updating record and deleting record in separate programs.

For basics, it is advised to go through Basic Steps of JDBC before going into this "Insert Update Delete Record JDBC" program.

Example on Insert Update Delete Record JDBC
import java.sql.*;
public class InsertUpdateDelete
  public static void main(String args[]) throws Exception
    Connection con = DriverManager.getConnection("jdbc:odbc:snrao", "scott", "tiger");
    Statement stmt = con.createStatement();

    stmt.executeUpdate("insert into Employee values(100, 'S N Rao'. 5500.50)");   // insert operation
    stmt.executeUpdate("update Employee set empsal=8000.50 where empid=101");     // insert operation
    stmt.executeUpdate("delete from Employee where empid=103");                   // insert operation

    System.out.println("Insert Update Delete Record JDBC are done");              

    stmt.close();                                                                 // close Statement object
    con.close();                                                                  // close Connection object


Once the con object of Connection is closed, the database connection with the Java program is disconnected. If required, must establish a new connection again.

The same above program is illustrated with JDBC with Transactions.

Pass your comments and suggestions to improve this tutorial "Insert Update Delete Record JDBC".

Leave a Comment

Your email address will not be published.