Skip to content

Instantly share code, notes, and snippets.

@fanjavaid
Created January 31, 2013 07:52
Show Gist options
  • Save fanjavaid/4681125 to your computer and use it in GitHub Desktop.
Save fanjavaid/4681125 to your computer and use it in GitHub Desktop.
public void getDoctorData() {
DoctorService doctorService = new DoctorService();
List<Doctor> list = doctorService.selectAll();
Vector vecModel = new Vector();
for (Doctor doctor : list) {
String name = doctor.getFirstname()+" "+doctor.getLastname();
int id = doctor.getId();
vecModel.addElement(new Doctor(id, name));
}
ComboBoxModel model = new DefaultComboBoxModel(vecModel);
cmbDoctor.setModel(model);
}
// Select All Data
public List<Doctor> selectAll() {
Statement stmt = null;
ResultSet rs = null;
List<Doctor> doctors = new ArrayList<>();
try {
stmt = conn.createStatement();
rs = stmt.executeQuery(selectAll);
while (rs.next()) {
Doctor doctor = new Doctor();
doctor.setId(rs.getInt("uid"));
doctor.setTitle(rs.getString("title"));
doctor.setFirstname(rs.getString("firstname"));
doctor.setLastname(rs.getString("lastname"));
doctor.setSpecialist(rs.getString("specialist"));
doctors.add(doctor);
}
return doctors;
} catch (SQLException se) {
se.printStackTrace();
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment