Populate a jTable Using MySQL
I have a project with a jTable
called AchTa开发者_StackOverflow社区ble
, that is like this:
+-------+------+ | File | Type | +-------+------+ | | | | | | | | | +--------------+
And I have a mySQL table that is like the same, then I want to know how could I populate the jTable
.
So what is the problem, creating a table or creating an SQL query?
Read the section from the Swing tutorial on How to Use Tables.
Read the tutorial on JDBC Database Access.
Put the two together and you've got your problem solved. That is first create your query and create a ResultSet. Then you use the meta data to get the column names. Then you loop through the ResultSet and add rows of data to your table. You can use a DefaultTableModel for this.
精彩评论