I am running in to an odd issue. I have a database with 6 different "bids". I am trying to extract the bids with the 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 * FROM bids WHERE 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 some reason my ArrayList result is giving me 6 identical "bid" objects instead of adding each of the "bids" from my database individually. The code runs through the ResultSet as expected and the correct values for each run is printed correctly if I add "System.out.println(bid.getBidID);" inside my while-loop. Can anyone tell me what is wrong with my code?
Thank you