The function need to be accomplished is:
- Select main group
- Select from sub-group (TEST NAME)
- Click >> button which means move the selection to Jtable
- Show the slected (Test) with corresponding price on Jtable
conditions:
- if the selected node (test name) alread has been selected and added to the Jtable show message say: Test name already added.
- we can select and add many test name
impotant to say that JTree data come from two tables main-group and sub-group
Here the code: of >> button
try {
DefaultMutableTreeNode selectedElement = (DefaultMutableTreeNode) TestTree.getSelectionPath().getLastPathComponent();
Object[] row = {selectedElement};
DefaultTableModel model = (DefaultTableModel) myTests_table.getModel();
System.out.println(String.valueOf(row).toString() + "Hi");
if (selectedElement.isLeaf() == true) {
//model.addRow(row);
// retrive date from DB price
String sql = "SELECT sub_group.name AS 'name', sub_group.price AS 'price'"
+ "FROM sub_group \n"
+ "where sub_group.name = '" + row + "' ";
pst = conn.prepareStatement(sql);
rs = pst.executeQuery(sql);
while (rs.next()) {
myTests_table.setModel(DbUtils.resultSetToTableModel(rs));
}
} else {
JOptionPane.showMessageDialog(null, "Please Choose Test name!", "Error", JOptionPane.WARNING_MESSAGE);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error");
}
Dears where is the error? Thanks