Insert record using Statement in Java

We saw how to Create Table using Statement in Java.
Now lets insert data into this table using Statement.

Insert record SQL

Below is the query that can be fired directly on database to insert record.

Method from Statement Interface used

“Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.”

Now lets see the sample code for firing this SQL using JDBC

Example : Insert record using Statement in Java


Since we have JDK 7, we are using Try-with-resources Statement to handle the resources that are opened.


1. Statement executeUpdate()