How to get data in MySQL table in Java JTable?

I am working on a Java project and I need to load a specific dataset into JTable . Can someone explain to me how to do this? These are my fields in the mrnform table in a 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,
+4
source share
4 answers

1) build JDBC Connection for MySql , examples here

2) load data into JTable using TableModel , examples here

3) if you answer a question, send this question here to sscce from

+7
source

Pseudo code

  • Create a TableModel (or Vector)
  • Establish a db connection and get the result.
  • Save the database result to a TableModel object.
  • Build JTable (tableModel).
+3
source

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

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

// create a connection to the database // execute the request // there is no launch cycle

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

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

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

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

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

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

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

// increment in jtable string. string ++; }} catch (Exception e) {

} '

0
source

All Articles