Java 如何告诉mysql表将下一条匹配记录检索到我的默认表模型中

Java 如何告诉mysql表将下一条匹配记录检索到我的默认表模型中,java,mysql,jtable,defaulttablemodel,data-retrieval,Java,Mysql,Jtable,Defaulttablemodel,Data Retrieval,如何告诉java程序将下一条匹配记录检索到默认表模型中 以下是我目前的家庭作业。我必须使用jTabletb1和默认表格模型dtm private void Show_My_LettersActionPerformed(java.awt.event.ActionEvent evt) { Connection conn = null; Statement stmt = n

如何告诉java程序将下一条匹配记录检索到默认表模型中

以下是我目前的家庭作业。我必须使用
jTable
tb1
和默认表格模型
dtm

 private void Show_My_LettersActionPerformed(java.awt.event.ActionEvent evt) {                                                
        Connection conn = null;
        Statement stmt = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

            System.out.println("Connecting to a selected database...");
            conn = DriverManager.getConnection(url, "root", "root");
            System.out.println("Connected database successfully...");

            System.out.println("Creating statement...");
            stmt = conn.createStatement();
            String sql = "SELECT * from LCI where SUB_ID = '" + SUB_ID_.getText() + "' AND L_DATE = '" + DATE.getText() + "'";
            ResultSet rs1, rs2, rs3, rs4, rs5, rs6, rs7;
            rs1=j.getData("select COUNT(*) from LCI");

            try (ResultSet rs = stmt.executeQuery(sql)) {
                DefaultTableModel dtm = (DefaultTableModel) tb1.getModel();
                while (rs.next()) {
                    String L_ID_ = rs.getString("L_ID");
                    String L_DATE_ = rs.getString("L_DATE");
                    String heading = rs.getString("HEADING");
                    String sub_id = rs.getString("SUB_ID");

                    System.out.print("ID: " + L_ID_);
                    System.out.print(", Letter date: " + L_DATE_);
                    System.out.print(", Heading " + heading);
                    System.out.println(", Subject ID " + sub_id);


/* This gives the correct out put when debug is done.
    But the below code doesn't retrive the full out put. 
    It gives only the very first record matching with the user inputs*/


                    Vector v = new Vector();
                    Vector v1 = new Vector();
                    Vector v2 = new Vector();
                    Vector v3 = new Vector();

                    JOptionPane.showMessageDialog(this, "Done");
                    dtm.getColumnName(1);
                    v.addElement(rs.getString(1));
                    dtm.addColumn(v);

                    dtm.getColumnName(3);
                    v1.addElement(rs.getString(3));
                    dtm.addColumn(v1);

                    dtm.getColumnName(10);
                    v2.addElement(rs.getString(10));
                    dtm.addColumn(v2);
                    // stmt.executeQuery("SELECT * FROM   LCI WHERE  L_ID IN(SELECT (L_ID + 1)FROM   LCI  WHERE  L_DATE = '"+DATE.getText()+"'");

                  dtm.addRow(v3);
                 //stmt.executeQuery("SELECT * FROM   LCI WHERE  L_ID IN(SELECT (L_ID '"+(+1)+"')FROM   LCI  WHERE  L_DATE = '"+DATE.getText()+"'");
                }
            }
        } catch (SQLException se) {
            se.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (stmt != null) {
                    conn.close();
                }
            } catch (SQLException se) {
                se.printStackTrace();
            }
            try {
                if (conn != null) {
                    conn.close();
                }
            } catch (SQLException se) {
                se.printStackTrace();
            }
        }// TODO add your handling code here:
    }   

请不要使用
Class.forName(“com.mysql.jdbc.Driver”)。自从12年前推出Java6以来,这就不再是必要的了。另外,您正在使用try with resources作为
结果集
,那么为什么不使用
连接
语句
?@SeverityOne呢。谢谢你。我会调查的。但是上面的代码成功地检索到了第一条匹配的记录。我需要的是将所有与条件匹配的记录检索到“jTable”“tb1”中,我确信它可以工作。它也已经过时12年了。