【问题标题】:How to fix getrowcount() in netbeans?如何修复netbeans中的getrowcount()?
【发布时间】:2020-09-14 04:41:18
【问题描述】:

我在java中的表连接到mysql。它检索表中的数据。但是当我指定 getrowcount() 时,它在 system.out.print 中显示 0 行。请帮忙,我们的项目截止日期是 6 月 3 日。

DefaultTableModel model = (DefaultTableModel) table.getModel();
    model.setRowCount(0);
try{
    Class.forName("com.mysql.cj.jdbc.Driver");
    conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/project","root","tiger");
    stmt = conn.createStatement();
    if(ch1.isSelected()){
    String query = "Select * from details where name like '"+d2.getText()+"%';";
    rs = stmt.executeQuery(query);
    System.out.print(table.getRowCount());
    }
    if(table.getRowCount() == 0){
        JOptionPane.showMessageDialog(null,"No records found");
    }
    while(rs.next()){
        int id;
        id = rs.getInt("userid");
        String name = rs.getString("name");
        String gender = rs.getString("gender");
        String dob = rs.getString("dob");
        String phno = rs.getString("phoneno");
        String doj = rs.getString("joindate");
        String doe = rs.getString("exitdate");
        model.addRow(new Object[]{id,name,gender,dob,phno,doj,doe});
    }
    rs.close();
    stmt.close();
    conn.close();
}
catch(ClassNotFoundException | SQLException e){
    JOptionPane.showMessageDialog(null,"Error");
}
            d1.setText("");
            d2.setText("");
            d3.setSelectedItem("");
            d4.setText("");
            d5.setText("");
            d6.setText("");
            d7.setText("");
            update.setEnabled(false);
            delete.setEnabled(false);

【问题讨论】:

  • 表在哪里声明?我看不到任何地方

标签: java mysql swing jtable defaulttablemodel


【解决方案1】:

请查看下面的 getRowCount() 为您提供了什么

您可以参考以下链接以获得更多说明 https://docs.oracle.com/javase/8/docs/api/javax/swing/JTable.html#getRowCount--

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    相关资源
    最近更新 更多