JAVA JDBC – Insert, Update, Select and Delete Data in MySQL Table

In this tutorial you will learn:

1. How to Insert, Update, Select and Delete Data from MySQL in JDBC?
2. Programming Example

In this tutorial you are going to learn insert, update, delete or select rows using JDBC. While developing Java Application it is almost the very important part. Most of the application lies on Database and they use Table to save and retrieve records. It is very important to have sound knowledge over data manipulation, if you want to be a perfect java developer. Here, I am attaching a simple program that will easily demonstrate insert, update, delete and search record in table using JDBC.

Programming Example

Output

Record Inserted Successfully
Closing the connection.
_

Retrieve Records

Once you inserted record you can retrieve record using ResultSet Object of JDBC. Here is the complete programming example of retrieving data from MySQL using JDBC.

Output

ID: 1 Product : ToothPaste Price : 200
ID: 2 Product : MousePad Price : 190
ID: 3 Product : Stationary Price : 2870
ID: 4 Product : Books Price : 765
ID: 5 Product : HardDisk Price : 3887
ID: 6 Product : Ram Price : 953
ID: 7 Product : Printer Price : 8746
ID: 8 Product : Keyboard Price : 646
ID: 9 Product : Mouse Price : 947
ID: 10 Product : JoyStick Price : 850
ID: 11 Product : Camera Price : 3252
Closing the connection.
_

Update and Delete Records

Updating and Deleting Records in MySQL using JDBC is so simple. You have to follow same procedure and execute update or delete command. Here is the complete program.

Programming Example

Output

Table Updated Successfully
Row Deleted Successfully
******** Records Are *********
ID: 1 Product : UsbCable Price : 200
ID: 2 Product : MousePad Price : 190
ID: 3 Product : Stationary Price : 2870
ID: 4 Product : Books Price : 765
ID: 5 Product : HardDisk Price : 3887
ID: 6 Product : Ram Price : 953
ID: 7 Product : Printer Price : 8746
ID: 8 Product : Keyboard Price : 646
ID: 10 Product : JoyStick Price : 850
ID: 11 Product : Camera Price : 3252
Closing the connection.
_

Summary

In this tutorial you learn to manipulate data like insert, update, select or delete records in MySQL Table using JDBC. Once you have completed this chapter you are now able to run your own query and get your desired result. In the next chapter you will learn to storing and retrieving image using JDBC.


Leave a Reply

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