LinkedList schools = new LinkedList();
while(rs.next ())
{
sbf.setProvince (rs.getString ( "s_province "));
sbf.setCity (rs.getString ( "s_city "));
sbf.setCounty (rs.getString ( "s_county "));
sbf.setSchoolName (rs.getString ( "s_schoolname "));
sbf.setSchoolAddr (rs.getString ( "s_addr "));
sbf.setXingzhi (rs.getString ( "s_character "));
sbf.setPeopleNum (rs.getInt ( "s_peopleNum "));
sbf.setMasterName (rs.getString ( "s_schoolmaster "));
sbf.setMasterPhone (rs.getString ( "s_masterphone "));
sbf.setMasterMobile (rs.getString ( "s_mastermobile "));
sbf.setNetName (rs.getString ( "s_netteacher "));
sbf.setNetPhone (rs.getString ( "s_netphone "));
sbf.setNetMobile (rs.getString ( "s_netmobile "));
sbf.setEmail (rs.getString ( "s_email "));
sbf.setNetStatus (rs.getString ( "s_netstatus "));
schools.addLast (sbf);
}
为什么我的输出内容总是得到的最后一条内容,schools.addLast (sbf);具体怎么样,放到哪?
------解决方案--------------------
sbf代表一个引用总是指向了同一个地址,后面的值总是把前面的值覆盖
所以你add后总是加了最后一个
所以你在循环最前面加上一句
*** sbf = new ***();
------解决方案--------------------
sbf要new在while里面
在循环外面声明一下就行了
------解决方案--------------------
sbf这个对象的NEW放在循环里面。