Java Reference
In-Depth Information
6.
In EnterEmpInfo, insert the following code to define the method populateTFs
private void
populateTFs() {
empNumTF.setText(emp.getEmpNum());
empNameTF.setText(emp.getEmpName());
empStreetTF.setText(emp.getEmpStreet());
cityTF.setText(emp.getEmpCity());
stateTF.setText(emp.getEmpState());
zipTF.setText(emp.getEmpZip());
empPRTF.setText(String.valueOf(emp.getPayRate()));
exmpChoice.select(String.valueOf(emp.getExemptions()));
}
Add the following as the last statement in the
EnterEmpInfo(Employee e)
method:
7.
this
.populateTFs();
8.
Run TNT, select Employee Application, Update Employee Information, and then select
employee number 111.
The Mary Worker information should be displayed in the text fields.
We will now add the insert and update functions to Employee, and then modify EnterEmpInfo to invoke
those functions
9.
In Employee, add the following methods:
private void
doUpdate(String update) {
try
{
stmt.executeUpdate(update);
}
catch
(SQLException e) {
System.out.println("Problem with " + update + e);
}
}
public void
doInsert() {
String insert = "INSERT INTO tntdb.employee " +
createValuesClause();
doUpdate(insert);
}
public void
doUpdate() {
String update = "UPDATE tntdb.employee " +
createSetClause() + createWhereClause();
doUpdate(update);
}
public void
doDelete() {
String delete = "DELETE FROM tntdb.employee " +
createWhereClause();
doUpdate(delete);
}