public List<PetDao> petDao() throws SQLException{
List<PetDao> dao = new ArrayList<PetDao>();
try {
PetDao pd = new PetDao();
String sql="select * from pet";
ps = data.getConn().prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
pd.setName(rs.getString(2));
dao.add(pd);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return dao;
}
这是在连接了Oracle的情况下访问数据
for(int i=0;i<face.petDao().size();i++){
PetDao pet = face.petDao().get(i);
System.out.println("第"+(i+1)+"个宠物,名字叫:"+pet.getName());
}
这是用for遍历数据
为什么我只能重复遍历Oracle里面的最后一条数据,没办法从头到尾遍历呢?