I am retrieving data from database and I have made up my custom method below and it only returns
private List<Users> getAllUsers() throws Exception{
//Create an object that will return a list object
List<Users> userList = new ArrayList();
s = null;
result = null;
try{
s = connect.createStatement();
result = s.executeQuery("SELECT * FROM users");
while(result.next()){
Users newUser;
newUser = convertRowsintoUsers(result);
userList.add(newUser);
}
}catch(SQLException e){
}finally {
close(s, result);
}
return userList;
}
private Users convertRowsintoUsers(ResultSet result) throws Exception{
int id = result.getInt("user_id");
String full_name = result.getString("full_name");
String auth = result.getString("auth");
String phone = result.getString("phone");
String email = result.getString("email");
//Creating an object of Users class that will be envoked
Users tempUser = new Users(id,full_name,auth,phone,email);
return tempUser;
}
public static void main(String[] args) throws Exception{
DatabaseDAO data = new DatabaseDAO();
System.out.println(data.getAllUsers());
}
[miloa.Users@7a36aefa, miloa.Users@17211155]
I expected the list if names of users from database