public void actionPerformed(ActionEvent e) {
String action = e.getActionCommand();
if(action.equals("Reset")){
title.setSelectedIndex(0);
forename.setText(null);
surname.setText(null);
age.setText(null);
contactNo.setText(null);
houseNo.setText(null);
streetName.setText(null);
districtName.setText(null);
cityName.setText(null);
postcode.setText(null);
healthPlan.setSelectedIndex(0);
treatment.setSelectedIndex(0);
}
How do I update my sql database with data from the textfield when I click the "Submit" button. I have written this code so far but nothing seems to be happening when I click submit, but the reset button works when it is clicked.
if(action.equals("Submit")){
Connection con = null;
String db="jdbc:mysql://stusql.dcs.shef.ac.uk/team009?user=team009&password=********";
try {
con = DriverManager.getConnection(db);
Statement bil = con.createStatement();
bil.execute("INSERT INTO Patient (ForeName, SurName, DateOfBirth, PhoneNumber, HouseNumber, PostCode) " +
"VALUES (forename.getText(),surname.getText,age.getText,contactNo.getText(),houseNo.getText(),postcode.getText())");
JOptionPane.showMessageDialog(null,"Inserted Successfully!");
}
catch (SQLException ex) {
ex.printStackTrace();
}
finally {
if (con != null)
try {
con.close();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
Please any help would be appreciated thanks.
"Inserted Successfully!"is not displayed, youactionCommandcould be wrong. Start by adding some debugging statements to track the flow through your code (printing theactionCommandto start with and some message about where you are in the code), if that doesn't seem to help, add break points and begin debugging your code...