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;
}
So I select a row in jTable then delete. that then turns the boolean dataSelected to false. But somehow, the first condition always executes even though there are still multiple data in the database.
Edit: is there a method that can check if database is empty?
if (jTable.getRowCount() == 0) {
JOptionPane.showMessageDialog(null, "Data is Empty", "Invalid Action", JOptionPane.ERROR_MESSAGE);
}
My classmate did this instead. Instead of checking the db4o, it just checks the tablerowcount since the table outputs all data from db4o anyways.