Display a table in JFrame UI from MySQL Table

Introduction :


   Many times while creating UI you come across difficulties like, how to display data to the user which is readable and looks good. Mostly labels are used to display text but for dynamic data, there's no good way to show them.

So, here is the way to display data in a table directly from the MySQL table on the UI using JTable and some tricks to read data from ResulSet object, the output from the MySQL database.


Implementation :


The following code should be added in the frame initialization methods.


Explanation :

Firstly creating the data structures to store the data values and the column names.
Looping through the ResultSet object and reading the data.
Looping through the ResultSetMetaData object, which returns the names of the table which we will use as column names.
Adding the JTable to JScrollPane, to make the Table scrollable.

Source :

I have a project on GitHub that implements such codes. It is a project of the Library Management System.



 

Popular posts from this blog

Audio de-noising using Python (Wavelets)

Using FFMPEG to trim your videos

Converting HTML5 Game for Android | 2 Methods