public static List<order> findbyname(String name)throws Exception{
DBconnection.initialize();
aStatement = DBconnection.aConnection.createStatement();
String sql = "select * from carorder where Yourname='"+name+"'";
List<order> list = new ArrayList<order>();
order aOrder=new order() ;
try{
ResultSet rs = aStatement.executeQuery(sql);
while(rs.next()){
aOrder.setId(rs.getString(1));
System.out.println(aOrder.getId());
aOrder.setType(rs.getString(2));
aOrder.setYourname(rs.getString(3));
aOrder.setYourSex(rs.getString(4));
aOrder.setTelphone(rs.getString(5));
aOrder.setAddress(rs.getString(6));
aOrder.setTime(rs.getString(7));
aOrder.setStatus(rs.getString(8));
list.add(aOrder);
}
System.out.println(list.get(0).getId());
rs.close();
}catch (SQLException e) {
System.out.println(e);
}
DBconnection.terminate();
return list;
}
}
第一个system打印出两个数据4,17
第二个system打印出来的是17
调用函数输出的结果是两条ID为17的数据,求解这是为什么?
------解决思路----------------------
order aOrder=new order() ;
放到while循环里面,再放外面打死你