I'm making this client formula and the list of clients is displayed in a JTable and sent to my SQL Database. I want a option saying if there is no name yet (a newborn, new business etc.) then the JCheckbox "unknown" is checked instead of filling the name in the JtextField area.
I think I should use the if-else statement.
addButton.addActionListener(new ActionListener() {
public void actionPerformed (ActionEvent arg0) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/num klienter", "root", "");
PreparedStatement pst = con.prepareStatement("INSERT INTO klient (Name,Birthday,Description) VALUES (?,?,?)");
if (unknownCB.isSelected()) {??what code to insert here??}
else { pst.setString(1, nameTxt.getText());}
pst.setString(2, dayTxt.getText()+"-" + monthTxt.getText()+"-" + yearTxt.getText());
pst.setString(3, descriptionTxt.getText());
pst.executeUpdate();
JOptionPane.showMessageDialog(null, "Saved in database");
upDateDB();
}catch (Exception ex){
JOptionPane.showMessageDialog(null, ex);
}}
});
Aucun commentaire:
Enregistrer un commentaire