-1

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

  • If you want consider spring jdbc or JPA easy and get rid of boilerplate code – JustTry Apr 26 '19 at 17:22
  • It looks like you just aren't printing the results properly. Can you edit your post with the code you use to print that output? – Chris K Apr 26 '19 at 17:34

1 Answers1

2

You should implement the toString() method in the Users class

Alex Mi
  • 1,409
  • 2
  • 21
  • 35