4

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,
2
  • Please edit your question to include you query. Commented Oct 1, 2011 at 14:28
  • Query should be any thing such as "Select * from mrnform" etc. Commented Oct 1, 2011 at 15:37

4 Answers 4

7

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

Sign up to request clarification or add additional context in comments.

3 Comments

How can I use it in net-beans I try to follow that guide line on NetBeans but it didn't work for me.
did you add MySql JDBC driver into your ClassPath, in Netbeans only add MySql JDBC driver to the libraries folder :-)
Thanks for your resources. I have done that by following guide line on those reference. Thank you very much. :)
3

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).

Comments

2

Read the manual for the JTable:

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

Comments

0

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) {

}'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.