SL_User
SL_User

Reputation: 1954

How to get data in MySQL table into Java JTable?

I'm working on Java project, and I need to load a particular set of data in to JTable. Can someone explain to me how to do this? These are my fields in the "mrnform" table in database called "order_processing".

`Date` varchar(10) NOT NULL,
`RegNo` int(11) NOT NULL,
`Description` varchar(50) NOT NULL,
`ItemNo` int(11) NOT NULL,
`Unit` varchar(10) NOT NULL,
`Quantity` int(11) NOT NULL,
`Delivery_Date` varchar(10) NOT NULL,
`Delivery_Address` varchar(10) NOT NULL,
`Site_Name` varchar(30) NOT NULL,

Upvotes: 4

Views: 16829

Answers (4)

V_Rajput
V_Rajput

Reputation: 21

visit http://netshor.blog.com/2013/12/31/how-to-get-data-from-mysql-to-jtable/

'//initialize row of jTable int row=0; //start try-catch try{

//create connection with database //execute query //no start loop

while(rs.next()){jTable1.setValueAt(rs.getString(1), row, 0);

jTable1.setValueAt(rs.getString(2), row, 1);

jTable1.setValueAt(rs.getString(3), row, 2);

jTable1.setValueAt(rs.getString(4), row, 3);

jTable1.setValueAt(rs.getString(5), row, 4);

jTable1.setValueAt(rs.getString(6), row, 5);

jTable1.setValueAt(rs.getString(7), row, 6);

//increament in row of jtable. row++; } } catch(Exception e) {

}'

Upvotes: 0

mKorbel
mKorbel

Reputation: 109823

1) construct JDBC Connection for MySql, examples here

2) load data to the JTable by using TableModel, examples here

3) if you'll reall question, post this question here in sscce from

Upvotes: 7

KV Prajapati
KV Prajapati

Reputation: 94653

Pseudo code

  1. Design the TableModel (or Vector)
  2. Establish the db connection and retrieve result.
  3. Store database result into TableModel object.
  4. Construct the JTable(tableModel).

Upvotes: 3

Headshota
Headshota

Reputation: 21449

Read the manual for the JTable:

http://download.oracle.com/javase/tutorial/uiswing/components/table.html

Upvotes: 2

Related Questions