问题描述
如何通过选择 Jtable 行获取信息,然后将不同表中的相关信息提供到另一个表中?我想显示我的发票信息,一旦我点击一个,我想显示与其相关的客户和产品。
try {
Connection connection;
connection = DriverManager.getConnection(DATABASE_URL,"root","");
Statement statement = connection.createStatement();
String query = "SELECT I.idInvoice,C.idCustomer,C.FirstName,C.Surname,C.Phone,C.Street,C.City,C.County,C.Eircode,P.idProduct,P.PName,P.Price,P.Brand,I.QuantityOrder\n" +
"FROM `Invoice` I \n" +
"JOIN `Customer` C on I.idCustomer = C.idCustomer \n" +
"JOIN `PRODUCT` P on I.idProduct = P.idProduct LIMIT 0,1000";
PreparedStatement pstat = null;
ResultSet rs = statement.executeQuery(query);
// Column name array
String[] columnNames = {"idInvoice","Date","QuantityOrdered","idCustomer","idProduct"};
String[] columnNames1 = {"idProduct","pName","Brand","Price","Quantity"};
DefaultTableModel tableModel = new DefaultTableModel(columnNames,0);
DefaultTableModel tableModel1 = new DefaultTableModel(columnNames,0);
// Get data from database
while (rs.next()) {
String idI = rs.getString("idInvoice");
String idC = rs.getString("idCustomer");
String idP = rs.getString("idProduct");
String date = rs.getString("Date");
String qOrdered = rs.getString("quantityOrder");
// Row data
String[] data = {idI,date,qOrdered,idC,idP};
// Add date to rows
tableModel.addRow(data);
}
// JTable creation and customization
table = new JTable(tableModel);
table.setPreferredScrollableViewportSize(table.getPreferredSize());
table.setFillsViewportHeight(true);
pTable.add(new JScrollPane(table),BorderLayout.CENTER);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)