Display the Database Records – Java Swing

Hello guys, Bushan here, welcome back to B2 Tech. In our previous article, we have discussed about Inserting values to MySQL Database. In this article, let’s display the database values in a JFrame form so let’s get started.

The first step is to drag and drop 3 labels and  1 button on to your JFrame form, give a unique name to all 3 labels, label_id, label_name, label_age

Now double-click on the Display button it will create an ActionPerformed event, and write the following code

At this point, if you run this application you will see the JFrame form and Display button when you click the Display button the last record in the database will be displayed on the labels

So now let’s see how to clear the textbox/textfield values with a single click. To do that first, let’s drag and drop a button on to the frame and change the text to Reset

After the constructor, let’s write the following code,

Now double-click on the reset button, call the reset() method inside of it,

Call the same reset() method even after the insert operation, so that it will clear all the textbox values after inserting a new record. Here is the complete source code,


About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

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