Java Reference
In-Depth Information
10.
In Employee, add the following code to create the getEmpNums method:
public ResultSet getEmpNums() {
String select =
new String("SELECT empnum FROM tntdb.employee ");
this .doSelect(select);
return rs;
}
The method getEmpNums defines the SQL statement that will retrieve all the employee numbers. The SQL
statement is assigned to the String variable named select and select is passed to the doSelect method for execution.
The doSelect method executes the SQL statement and assigns the results to rs. getEmpNums then returns rs to the
calling method (i.e., the client).
11.
Create a new Java class called EmpNumFrame and enter the following code:
package c10;
import java.awt.Choice;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.sql.*;
public class EmpNumFrame extends UsefulFrame
implements ItemListener {
private String empNum, txType;
private Choice EmpNumCh = null ;
private Employee emp = new Employee();
public EmpNumFrame(String tx) {
super ();
initialize();
txType = tx;
}
private void initialize() {
this .setSize(278, 125);
this .setLocation(450, 303);
this .setLayout( null );
this .add(getEmpNumCh(), null );
this .setTitle("Select Employee Number");
this .setVisible( true );
}
private Choice getEmpNumCh() {
if (EmpNumCh == null ) {
EmpNumCh = new Choice();
EmpNumCh.setBounds(85, 59, 108, 21);
EmpNumCh.addItemListener( this );
ResultSet rs = emp.getEmpNums();
try {
while (rs.next()) {
EmpNumCh.add(rs.getString(1));
}
} catch (SQLException e) {
System.out.println("No connection: " + e);
}
 
Search WWH ::




Custom Search