In this tutorial you will learn about JDBC INSERT statement.

Subject: JDBC INSERT statement

Inserting data into a SQL database table is a simple two-step process:

First we need to create a Java Statement object.

Post creation of Java Statement object we need to execute a SQL INSERT command through the JDBC Statement object.

If anyone is aware of basic SQL queries, this is very easy to learn.

How to execute the JDBC INSERT statement

Here’s an example of how to create a Statement object, and then insert a record for a person named Mr. Rahul, of a town named Bangalore:

// create a Statement from the connection

Statement statement = conn.createStatement ();

// insert the data

statement.executeUpdate (“INSERT INTO Customers “+ “VALUES (1001, ‘Rahul’, ‘Mr.’, ‘Bangalore’, 2001)”);

JDBC Insert Example with Java Program:


* JdbcInsertExample.java basic program about how to INSERT data into an SQL

* Database using Java JDBC.


import java.sql.*;

class JdbcInsertExample {

public static void main (String [] args) {

try {

String url = “jdbc:msql://”;

Connection conn = DriverManager.getConnection (url,””,””);

Statement st = conn.createStatement ();

st.executeUpdate (“INSERT INTO Customers” +

“VALUES (1001, ‘Rahul’, ‘Mr.’, ‘Bangalore’, 2001)”);

conn.close ();


catch (Exception e) {

System.err.println (“Got an exception! “);

System.err.println (e.getMessage ());





Readers might read also:

Facebook Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.