我正在从数据库中检索数据,并且在下面构成了我的自定义方法,它仅返回
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]
如果来自数据库的用户名,我希望得到该列表
答案 0 :(得分:2)
您应该在Users类中实现toString()方法