ArrayList, LinkedList之类的数据,
当add时,需要要new一个对象,或者定义一个新的对象,才能add进来。
如果说,int tem = new int();
然后 for(int i = 0; i < 10; i++)
{
tem = i;
list.add(tem);
}
这样是不行的,因为tem是一个对象,add多少次,add进来的值都是最后一个tem对象。list元素里面放的都是指针,这个指针指向tem对象。下面的代码才是正确的:
然后 for(int i = 0; i < 10; i++)
{int tem = new int();
list.add(tem);
}
下面的代码是开发车险时的相关的问题,已经改成正确的
public List<CarInsurOrderCarInfo> findOrderCarInfo(String brchNo,
String sDate, String eDate, String carID, String statusInput,
String companyNo) {
try {
Session session = getHibernateTemplate().getSessionFactory()
.getCurrentSession();
/*
String queryString = "select t1.orderid,t1.companyid,t1.carnumber,t1.payamt,t2.companyName from T33CarinsuranceOrder as t1,"
+ "T33CarinsuranceCompany as t2 where t1.txnbranch='"
+ brchNo
+ "' and t1.orderstatus='02' and t1.companyid=t2.companyId";
*/
//String queryString = "select t.seq1, t.orderid, t.orderstatus, t1.name, t.carnumber, t.companyid, t2.company_name, t.compreappno, t.commerceappno, t.datezhifu, t1.shenfenID from T33CarinsuranceOrder t, customerQT t1, CarInsurCompany t2 where t.carnumber = t1.carNum and t.companyid = t2.company_id ";
String queryString = "select t.seq1, t.orderid, t.orderstatus, t1.name, t.carnumber, t.companyid, t2.company_name, t.compreappno, t.commerceappno, t.datezhifu, t1.shenfenID from T33CarinsuranceOrder t, customerQT t1, CarInsurCompany t2 ";
System.out.println(queryString);
Query query = session.createQuery(queryString);
List result = query.list();
List list = new ArrayList();
//List list = new LinkedList();
Iterator it = result.iterator();
int tableSeq = 1;
while (it.hasNext()) {
System.out.println("into while");
CarInsurOrderCarInfo rowinfo=new CarInsurOrderCarInfo();
Object[] object=(Object[]) it.next();
String seq1=(String) object[0];
String orderid=(String) object[1];
String status = (String) object[2];
String ownerName=(String) object[3];
String carnumber=(String) object[4];
String companyid=(String) object[5];
String company_name=(String) object[6];
String compreappno=(String) object[7];
String commerceappno=(String) object[8];
String datezhifu=(String) object[9];
String ownerID=(String) object[10];
rowinfo.setTableSeq(tableSeq);
rowinfo.setSeq1(seq1);
rowinfo.setStatus(status);
rowinfo.setOrderid(orderid);
rowinfo.setOwnerID(ownerID);
rowinfo.setOwnerName(ownerName);
rowinfo.setCarnumber(carnumber);
rowinfo.setCompanyid(companyid);
rowinfo.setCompany_name(company_name);
rowinfo.setCompreappno(compreappno);
rowinfo.setCommerceappno(commerceappno);
rowinfo.setDatezhifu(datezhifu);
tableSeq++;
list.add(rowinfo);
System.out.println(rowinfo.getCompany_name());
System.out.println(list.size());
}