无法在Java循环中将对象添加到列表中

时间:2014-09-17 11:26:03

标签: java object arraylist

我试图将一个对象添加到循环内的列表中。当我打印对象时,它显示正确的值。但是当我打印列表时,它会显示列表的最后一个元素,它打印的时间数等于列表的大小。

这是附带的代码。

static List<CastIronProjects> allProjDetails;

allProjDetails = new ArrayList<CastIronProjects>();

// Connect to DB and querying the table
stmt = conn.createStatement();
String query = "SELECT * FROM CASTIRONPROJECTS";
rs = stmt.executeQuery(query);

// Extract data from the resultset
while(rs.next())
{
    CastIronProjects projDetails = new CastIronProjects();

    projDetails.setEmailAddress(rs.getString("EMAILADDRESS"));
    projDetails.setFrequency(rs.getString("FREQUENCY"));
    projDetails.setLastSuccessfulEndTime(rs.getDate("LASTSUCCESSFULENDTIME"));
    projDetails.setLastSuccessfulRunTime(rs.getDate("LASTSUCCESFULSTARTTIME"));
    projDetails.setMaxRunningTime(rs.getLong("MAXRUNNINGTIME"));
    projDetails.setOrchName(rs.getString("ORCHESTRATIONNAME"));
    projDetails.setOrchType(rs.getString("ORCHESTRATIONTYPE"));
    projDetails.setProjId(rs.getString("PROJECTID"));
    projDetails.setProjName(rs.getString("PROJECTNAME"));
    projDetails.setProjOwner(rs.getString("PROJECTOWNER"));
    projDetails.setRunsEvery(rs.getInt("RUNSEVERY"));
    projDetails.setVersion(rs.getFloat("VERSION"));

    allProjDetails.add(projDetails);

}

你能帮帮我吗?

CastIronProjects类的代码

import java.util.Date;

public class CastIronProjects 
{
public static String projId;
public static String projName;
public static String orchName;
public static String projOwner;
public static String orchType;
public static int runsEvery;
public static String frequency;
public static Date lastSuccessfulStartTime;
public static Date lastSuccessfulEndTime;
public static float version;
public static long maxRunningTime;
public static String emailAddress;

public static String getProjId() 
{
    return projId;
}
public static void setProjId(String projId) 
{
    CastIronProjects.projId = projId;
}
public static String getProjName() 
{
    return projName;
}
public static void setProjName(String projName) 
{
    CastIronProjects.projName = projName;
}
public static String getOrchName() 
{
    return orchName;
}
public static void setOrchName(String orchName) 
{
    CastIronProjects.orchName = orchName;
}
public static String getProjOwner() 
{
    return projOwner;
}
public static void setProjOwner(String projOwner) 
{
    CastIronProjects.projOwner = projOwner;
}
public static String getOrchType() 
{
    return orchType;
}
public static void setOrchType(String orchType) 
{
    CastIronProjects.orchType = orchType;
}
public static int getRunsEvery() 
{
    return runsEvery;
}
public static void setRunsEvery(int runsEvery) 
{
    CastIronProjects.runsEvery = runsEvery;
}
public static String getFrequency() 
{
    return frequency;
}
public static void setFrequency(String frequency) 
{
    CastIronProjects.frequency = frequency;
}
public static Date getLastSuccessfulRunTime() 
{
    return lastSuccessfulStartTime;
}
public static void setLastSuccessfulRunTime(Date lastSuccessfulRunTime) 
{
    CastIronProjects.lastSuccessfulStartTime = lastSuccessfulRunTime;
}
public static Date getLastSuccessfulEndTime() 
{
    return lastSuccessfulEndTime;
}
public static void setLastSuccessfulEndTime(Date lastSuccessfulEndTime) 
{
    CastIronProjects.lastSuccessfulEndTime = lastSuccessfulEndTime;
}
public static float getVersion() 
{
    return version;
}
public static void setVersion(float version) 
{
    CastIronProjects.version = version;
}
public static long getMaxRunningTime() 
{
    return maxRunningTime;
}
public static void setMaxRunningTime(long maxRunningTime) 
{
    CastIronProjects.maxRunningTime = maxRunningTime;
}
public static String getEmailAddress() 
{
    return emailAddress;
}
public static void setEmailAddress(String emailAddress) 
{
    CastIronProjects.emailAddress = emailAddress;
}

}

0 个答案:

没有答案