Java JDBC – Statement Object to Execute Insert, Update and Delete

In this chapter you will learn:

1. What is Statement Interface in Java JDBC?
2. How to use Statement Object to execute Insert, Update, Select and Delete Query

What is Statement Interface in Java JDBC?

Statement Object is used for executing sql query like Insert, Update, Delete and Select in the database. It provides methods to execute queries with the database.

Programming Example

Select Record in ResultSet using Statement


ID: 1, PRODUCT: MousePad, Price: 190
ID: 2, PRODUCT: Stationary, Price: 2870
ID: 3, PRODUCT: Books, Price: 765
ID: 4, PRODUCT: HardDisk, Price: 3887
ID: 5, PRODUCT: Ram, Price: 953
ID: 6, PRODUCT: Printer, Price: 8746
ID: 7, PRODUCT: Keyboard, Price: 646
ID: 8, PRODUCT: Mouse, Price: 947
ID: 9, PRODUCT: HDMI CABLE, Price: 850
ID: 11, PRODUCT: Charger, Price: 1800
ID: 12, PRODUCT: MainJava Logo, Price: 900

Insert Row in Table using Statement


Row Inserted
Closing the connection.

Update Record in Table using Statement

Row Updated
Closing the connection.

Delete Row in Table using Statement


Row Deleted
Closing the connection.


It is very easy to use Statement Interface in JDBC programming for executing queries in database. However, it is not efficient way to run query in database. Instead of Statement you can use PreparedStatement, which is efficient and faster than Statement Object. In the next chapter you will learn about PreparedStatement in JDBC.

Leave a Reply

Your email address will not be published. Required fields are marked *