我试图获取特定日期之间的所有数据,但JTtable不会在表格中显示第一条记录。我有什么问题吗?
String qry = "SELECT * FROM records where bill_issued_on between ? and ? and area=?";
try {
PreparedStatement p = db.getCon().prepareStatement(qry);
p.setDate(1, sqlDateObjectStart);
p.setDate(2, sqlDateObjectEnd);
p.setString(3, area);
ResultSet rs = p.executeQuery();
while (rs.next()) {
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
confirmationLabel.setText("Records Found");
}
} catch (Exception e) {
System.out.println("Problem in query \n" + e);
}
答案 0 :(得分:3)
ResultSet rs = p.executeQuery();
while (rs.next()) {
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
confirmationLabel.setText("Records Found");
}
不要使用while循环。 DbUtils类将根据ResultSet中的值创建TableModel。
ResultSet rs = p.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
confirmationLabel.setText("Records Found");