How to get data in MySQL table into Java JTable?

2020-07-18 02:56发布

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,

4条回答
Luminary・发光体
2楼-- · 2020-07-18 03:04

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

查看更多
对你真心纯属浪费
3楼-- · 2020-07-18 03:06

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

}'

查看更多
欢心
5楼-- · 2020-07-18 03:23

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).
查看更多
登录 后发表回答