java代码求救

来源:百度知道 编辑:UC知道 时间:2024/05/24 04:56:07
1. 读如下代码,回答问题。
try {
PreparedStatement ps = conn.prepareStatement(SQL);
rs = ps.executeQuery();
List resultList = new ArrayList();
int n=0;
if(rs!=null){
----------------------------------------------①
while(rs.next())
{
MissionVO mission=new MissionVO(); ------------② int a[];
mission.setProId(rs.getInt("ProId"));
mission.setWEndDate(rs.getDate("WEndDate"));
resultList.add(mission);
n++;
}
rs.close();
conn.close();
if (n>0){
return resultList;
}else{
return null;
}
}else{
rs.close();
conn.close();
return null;
}
}
catch ( Exception e){
conn.close();
return null;
}

1.你这段代码int a[]那里都没有引用啊。你移到1处,没什么问题。
2.MissionVO是一个具有默认构造器的Bean类
3,至少具有 int ProId,Date WEndDate;
原型很好写啊
public class MissionVO{
public void setProId(int ProId){
this.ProId=ProId;
}
public void setWEndDate(Date WEndDate){
this.WEndDate=WEndDate;
}
public int getProId(){
return this.ProId;
}
public void getWEndDate(){
return this.WEndDate;
}
}
最后鄙视一下楼主,抠人,一分都不给
放在2处是放在循环里面,循环一次,生次一个bean对象,可以生成很多对象。本题是正确的
放在一处,只生成了一个对象。循环中只是改变了属性值而已。你在List中只能得到最后一个对象,仅仅只能得到一个对象。