0
public class UserBean<br>
{ 
 public String name; 
 public String role; 
} 

class Dao{ 
 ArrayList<UserBean> a = new ArrayList<UserBean>();
 String sql = "Select * from user";
 ResultSet rs = pStmt.executeQuery(sql);
 while(rs.next()){
 //----------Problem------------
 // i want to do something like<br>
  a.add[0].name = rs.getString("name");
  a.add[0].role = rs.getString("role");
 // Get column from resultset and set the value of userbean column
 }
}
1
  • sorry line no 9 is ArrayList<UserBean> a= new ArrayList<UserBean>(); Commented Oct 17, 2011 at 4:09

2 Answers 2

4

Create an instance of UserBean and add it to the List.

 while(rs.next()){
  UserBean bean=new UserBean();
  bean.name = rs.getString("name");
  bean.role = rs.getString("role");
  a.add(bean);
 // Get column from resultset and set the value of userbean column
 }
Sign up to request clarification or add additional context in comments.

Comments

1

You can try:

public class UserBean {
    public String name;
    public String role;
}

class Dao{
    ArrayList<UserBean> a= new ArrayList<UserBean>();
    String sql = "Select * from user";
    ResultSet rs = pStmt.executeQuery(sql);
    while(rs.next()){
        UserBean ub = new UserBean();
        ub.name=rs.getString("name");
        ub.role=rs.getString("role");
        a.add(ub);

    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.