database - Java ArrayList acting up -


i running in odd issue. have database 6 different "bids". trying extract bids following code:

public arraylist<projectbid> getprojectbids(string projectid)     {         arraylist<projectbid> result = new arraylist<projectbid>();          projectbid bid = new projectbid();          try{          st = con.createstatement();         string query = "select * bids projectid=\""+projectid+"\"";         system.out.println(query);         resultset rs = st.executequery(query);           while (rs.next())           {             bid.setprojectid(projectid);             bid.setbidid(rs.getstring("bidid"));             bid.setbidderemail(rs.getstring("bidder_email"));             bid.setbidamount(rs.getint("bid_amount"));             bid.setbidmessage(rs.getstring("bid_message"));             bid.settimestamp(rs.getstring("timestamp"));              result.add(bid);           }           st.close();          }         catch(exception ex){             system.out.println("exception: "+ex);         }          return result;               } 

for reason arraylist result giving me 6 identical "bid" objects instead of adding each of "bids" database individually. code runs through resultset expected , correct values each run printed correctly if add "system.out.println(bid.getbidid);" inside while-loop. can tell me wrong code?

thank you

you should move projectbid bid = new projectbid(); inside while loop. current code updating same bid variable defined outside while loop hence gets last record's value after loop completes.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -