Abdul Qadir
Abdul Qadir

Reputation: 7

JTable not displaying all the records

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

Answers (1)

camickr
camickr

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

Related Questions