Java Reference
In-Depth Information
} catch (SQLException e) {
System.out.println("Problem getting emp info from"
+ " result set " + e);
} catch (InvalidValue e) {
System.out.println("Bad pay rate value retrieved " + e);
}
}
This will set the Employee object's properties to the information retrieved from the Employee table (which is in
the result set rs). This is one of the private methods that the clients don't need to know about. In other words, clients
will never have to deal with SQL statements, database-related objects (result sets, connections, etc.), or methods
(getString, getStatement, etc).
2.
In Employee, add a new method called getEmpInfo by inserting the following code:
public void getEmpInfo(String empNum) {
String select = new String("SELECT * FROM " +
"tntdb.employee WHERE empnum = '" + empNum + "'");
this .doSelect(select);
this .getEmpInfoFromRS();
}
This method builds the select statement, invokes doSelect to retrieve the data, and then invokes
getEmpInfoFromRS to set the object's properties.
Now we will change EmpNumFrame to invoke getEmpInfo for the employee number (specified by the user)
and then create an EmployeeFrame object to display the information.
3.
In EmpNumFrame's itemStateChanged method, replace the println statement with the
following:
emp.getEmpInfo(empNum);
if (txType.equals("display")) {
EmployeeFrame ef = new EmployeeFrame(emp);
}
Let's test.
4.
Run TNT as an application.
5.
On the Application Menu, select Employee Application.
6.
On the Employee Application Menu, select Display Employee Information.
7.
On the Select Employee Number frame, click on the choice arrow and select employee
number 222.
The Select Employee Number frame will disappear and the Employee Information frame will be displayed with
the Joe Programmer information.
8.
Click the Exit button on the Employee Information frame to close all frames.
Well, display was fairly easy to implement.
For updates, we must change the EnterEmpInfo frame to receive the Employee object (from EmpNumFrame),
display the properties, and then update the data in the Employee table.
For inserts, the EnterEmpInfo frame must create an Employee object and then issue the command to insert the
data. Oh, and we have to create methods in Employee to insert and update the information in the table.
 
Search WWH ::




Custom Search