为什么即使数据库不是,它也总是输出空?

Why does it always outputs empty even when the database is not?

private booolean dataSelected = false;
private void jDeleteActionPerformed(java.awt.event.ActionEvent evt) {                                        
    ObjectContainer db = Db4oEmbedded.openFile("barangay_data.db4o");
    try {
        Brgy_Data brgy = new Brgy_Data(idno, null, null, null, null, null, null, null, null, null);
        ObjectSet result = db.queryByExample(brgy);
        if (result.isEmpty()) {
            JOptionPane.showMessageDialog(this, "Data is Empty", "Delete", JOptionPane.INFORMATION_MESSAGE);
        } else if (dataSelected == false) {
            JOptionPane.showMessageDialog(null, "No Data Selected!", "Invalid Action", JOptionPane.ERROR_MESSAGE);
        } else {
            Brgy_Data brgy1 = new Brgy_Data(null, null, null, null, null, null, null, null, null, null);
            brgy1 = (Brgy_Data) result.next();
            String msg = "Delete Data?\n";
            msg = msg + "First Name: " + brgy1.getFName() + "\n";
            msg = msg + "Last Name: " + brgy1.getLName() + "\n";
            int retval = JOptionPane.showConfirmDialog(this, msg, "Delete", JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE);
            if (retval == JOptionPane.YES_OPTION) {
                db.delete(brgy1);
                javax.swing.JOptionPane.showMessageDialog(this, "Data Successfully Deleted", "Delete", javax.swing.JOptionPane.INFORMATION_MESSAGE);

            }
        }
    } catch (Exception e) {
        System.out.println(e);
    } finally {
        db.close();
    }
    clearTable();
    loadDataInfo();
    dataSelected = false;
}

所以我select jTable 中的一行然后删除。然后将布尔 dataSelected 变为 false。但是不知何故,即使数据库中仍然有多个数据,第一个条件总是执行。

编辑:有没有一种方法可以检查数据库是否为空?

if (jTable.getRowCount() == 0) {
        JOptionPane.showMessageDialog(null, "Data is Empty", "Invalid Action", JOptionPane.ERROR_MESSAGE);
}

我的同学这样做了。它不检查 db4o,而是检查 table行数,因为 table 无论如何都会从 db4o 输出所有数据。