• Post Reply Bookmark Topic Watch Topic
  • New Topic

List Problems  RSS feed

 
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am executing a Java code segment which would retrieve information from the database and it would be added to a map and this map would be added to a list
*******************************************************

while (rs.next()) {
r = rs.getString("SamId");//working
// r=rs.getArray("SamId");//working
s= rs.getString("HistAt");//working
t= rs.getString("Name");//working
u= rs.getString("SerialNo");//working
System.out.println("r+s+t+u"+r+s+t+u);

dd.put("SamId",r);//entering it in a Map working
dd.put("HistAt",s);//working
dd.put("Name",t);//working
dd.put("SerialNo",u);//working


System.out.println("dd"+dd);
dele.add(dd);//adding to a List--working but problem is that instead of me getting a List of 10 columns containg different records, I am getting 10 colums of same record
System.out.println("dele"+dele);


}



Please help,
 
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is dd static?
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No its not static, I just found the solution, within the while statement dd has to be instantiated using the new Key word, So every iteration of the while statement results in a different Map object

while (rs.next()) {
Map dd=new Hashtable();
r = rs.getString("SamId");
//Object adew=rs.getObject("SamId");

// r=rs.getArray("SamId");
s= rs.getString("HistAt");

Thank you all, Suggestions are still very much welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!