Reputation: 7
I am trying to get all the data between specific dates, but the JTtable does not display 1st record in the table. Is there any thing I am doing wrong?
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);
}
Upvotes: 0
Views: 366
Reputation: 324128
ResultSet rs = p.executeQuery();
while (rs.next()) {
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
confirmationLabel.setText("Records Found");
}
Don't use a while loop. The DbUtils class will create a TableModel based on the values in the ResultSet.
ResultSet rs = p.executeQuery();
jTable1.setModel(DbUtils.resultSetToTableModel(rs));
confirmationLabel.setText("Records Found");
Upvotes: 3