[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Populating a JTable with the data from the MySQL database

Posted on 2009-02-15
6
Medium Priority
?
1,418 Views
Last Modified: 2012-05-07
Hi,

could someone show me how to populate a JTable with the query results from the MySQL database. I'm having some problems with the TableModel and don't exactly know how to approach the problem. JTable requires a Object[][] type of data and I don't know how to insert the query results inside. The database tables are: products, expiration, manufacturer, directions and fields that are to be into the JTable: products.name, products.manufacturer_id (points to manufacturer table), products.directions_id (points to directions table), expiration.date, expiration.supply.

Thanks!
0
Comment
Question by:slavenweb
  • 3
  • 2
6 Comments
 
LVL 92

Expert Comment

by:objects
ID: 23644612
0
 
LVL 92

Expert Comment

by:objects
ID: 23644617
sorry, misread :) for a JTabel see here

http://www.rgagnon.com/javadetails/java-0309.html

0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1200 total points
ID: 23644621
Just create a TableModel from the ResultSet. See

http://technojeeves.com/joomla/index.php/free/59-resultset-to-tablemodel
0
Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

 
LVL 92

Assisted Solution

by:objects
objects earned 400 total points
ID: 23644632
If passing the data to the constructor you want each row in the data array to be a row in the table, and thus a row from your result set

http://www.java2s.com/Code/JavaAPI/javax.swing.table/newDefaultTableModelObjectdataObjectcolumnNames.htm

0
 

Author Closing Comment

by:slavenweb
ID: 31623660
Thanks very much, it works!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 23645843
:-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question