java无法使用两个类从ResultSet填充jTable
我有一个查询类和另一个GUI类。因此,在我的GUI课程中,我有以下public成员:
model = (DefaultTableModel) table.getModel();
table = new JTable();
在查询类中,我有以下方法:
public void selectPassengers(int rows) {
PreparedStatement pst = null;
ResultSet rs = null;
String query = "SELECT * FROM brs.passenger";
try {
pst = con.prepareStatement(query);
rs = pst.executeQuery();
String[] attributes = new String[9];
GUI rg = new GUI();
while (rs.next()) {
attributes[0] = rs.getString(1);
attributes[1] = rs.getString(2);
attributes[2] = rs.getString(3);
rg.model.insertRow(rg.table.getRowCount(), new Object[] {
attributes[0], attributes[1], attributes[2]});
}
} catch (Exception e) {
e.printStackTrace();
}
}
它既不插入也不抛出异常。它什么都没用。尽管我尝试打印到while-loop
中的控制台,但它会打印正确的数据。数据库和连接正常
在执行查询之后,我应该在GUI类中做些什么吗
捷径没问题!我在寻找最简单的方法
共 (0) 个答案