I am querying a database to return a list of values based on an input string; and these list of values are displayed in a searchbox for the user. The issue is, my returned lists are being displayed as objects instead of a list of names. Attached are snippets of code to illustrate my point
my retrieve method
public List<EmployeeDetails> getEmployeeByName(String employeeName) {
List<EmployeeDetails> list=new ArrayList<EmployeeDetails>();
Connection c=null;
String sql=("SELECT * FROM employee_table WHERE UPPER(employeeName) LIKE ? ORDER BY employeeName");
try{
c = ConnectionHelper.getConnection();
PreparedStatement ps=c.prepareStatement(sql);
ps.setString(1, "%" + employeeName.toUpperCase() + "%");
ResultSet rs=ps.executeQuery();
while(rs.next()){
list.add(new EmployeeDetails (rs.getInt("employeeid"),
rs.getString("employeeName"),
rs.getString("employeeAddress"),
rs.getString("employeeAge"),
rs.getString("nationality"),
rs.getString("salaryRate")));
}
}catch (SQLException e) {
e.printStackTrace();
try {
throw new Exception(e);
} catch (Exception e1) {
e1.printStackTrace();
}
} finally {
ConnectionHelper.close(c);
}
return **list**;
}
i intend the searchbox be populated with only the names of the returned objects, not the raw encapsulated object. How do i go about this? Any help/pointers would be highly appreciated