我有几个“商品”对象,需要使用zipCode请求数据库。这些请求正在运行,但是如果我想打印出几个地理对象,则该方法刚刚保存了最后一个zipCode答案。
public void getGeoInfo_From_Database() {
Connection aCon = Persistence.getConnection();
ResultSet resultSet = null;
this.geoinfo = new ArrayList<Geoinfo>();
{
try {
for (Merchandise m : this.merchandise)
resultSet = Persistence.executeQueryStatement(
aCon,
"SELECT * from MERCHANDISETABLE where zipcode=" + h.getAddress().getZipcode());
while (resultSet.next()) {
Geoinfo g1 = new Geoobject();
g1.setLocid(resultSet.getString("LOC_ID"));
g1.setLongitude(resultSet.getString("LON"));
g1.setLatitude(resultSet.getString("LAT"));
g1.setZipCode(resultSet.getString("ZIPCODE"));
g1.setCity(resultSet.getString("City"));
this.geoinfo.add(g1);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
Persistence.closeConnection(aCon);
}
}
}
public void printGeoinfoList() {
for (Geoinfo g : this.geoinfo) {
System.out.println(g.toString());
}
}