I have jList and DB the DB have first name , last name , id and email
the jList will only display the first name , last name and id
what I'm trying to do is when the user select item in the jList the email will appear in the left side in textbox
here is what i did , but I want a better why if there is cuz I think my way is not good enough
what I did is the class of Person I did this for the to string method
@Override
public String toString() {
return id + " | "+ fname + " "+ Lname;
}
// I already managed to connect DB to JList here
public void fill() {
model = new DefaultListModel();
ResultSet rs = null;
try {
Connection conn = ConnectionManager.getConnection();
Statement st = conn.createStatement();
rs = st.executeQuery("select * from person");
while (rs.next()) {
int id = rs.getInt("ID");
String fname = rs.getString("FirstName");
String lName = rs.getString("LASTNAME");
String email= rs.getString("EMAIL");
person p = new person(fname, lName, id,email);
model.addElement(p);
ListPerson.setModel(model);
rs.close();
st.close();
}
} catch (SQLException ex) {
}