I have some methods that delete, update and put some data to the database (MySQL). I can check by myself that the data was added, deleted, and updated but I want some tests on my project.
How can I do it?
I use the code below to get the first and last names for the database using the ID (Primary_Key).
public void checkId() {
int idNumber = 0;
try {
idNumber = Integer.parseInt(textFieldForId.getText());
} catch (NumberFormatException ex) {
messageLabel.setText("PLEASE ENTER A NUMERIC VALUE");
}
try {
Connection con = DataBaseConnecction.getDataBaseConnection();
Statement statement = con.createStatement();
String sql = "select firstName , lastName from patients_info where id = " + idNumber;
ResultSet result = statement.executeQuery(sql);
while (result.next())
patientFullName.setText(result.getString("firstName") + " " + result.getString("lastName"));
} catch (Exception e) {
e.printStackTrace();
}
if (patientFullName.getText().isEmpty() && messageLabel.getText().isEmpty())
messageLabel.setText("THERE IS NO PATIENT WITH THIS ID NUMBER");
}
void deletePatient() {
int idNumber;
idNumber = Integer.parseInt(textfieldforCin.getText());
try {
Connection con = DataBaseConnecction.getDataBaseConnection();
String sql = "delete from patients_info where id = " + "'" + idNumber + "'";
int roweffected = con.createStatement().executeUpdate(sql);
messagelabel.setText("DELETED SUCCESS ");
} catch (SQLException ex) {
ex.printStackTrace();
} catch (NumberFormatException E) {
messagelabel.setText("SET A CORRECT CIN NUMBER ");
}
}