主题:关于Connection的问题,我快疯了!!回帖加分
请教大家个问题:
Collection list=new ArrayList();
TeacherBean tb=new TeacherBean();
try{
stm=con.createStatement();
rst=stm.executeQuery("select * from teacher");
while(rst.next())
{
tb.setAccount(rst.getString("tid"));
tb.setPassword(rst.getString("tpwd"));
tb.setUsername(rst.getString("tname"));
tb.setSex(rst.getString("sex"));
tb.setDepartment(rst.getString("department"));
}
rst.close();
stm.close();
}
catch(Exception e)
{
System.out.println("mei jie guo");
}
Iterator it=list.iterator();
while(it.hasNext())//显示存在问题
{
TeacherBean teab=(TeacherBean)(it.next());
System.out.print(teab.getAccount());//就是这句输出有问题
}
以上是部分代码,本来是应该输出所有的记录,可是结果循环输出了最后一条记录
求大家了,帮帮忙!!谢了!!
Collection list=new ArrayList();
TeacherBean tb=new TeacherBean();
try{
stm=con.createStatement();
rst=stm.executeQuery("select * from teacher");
while(rst.next())
{
tb.setAccount(rst.getString("tid"));
tb.setPassword(rst.getString("tpwd"));
tb.setUsername(rst.getString("tname"));
tb.setSex(rst.getString("sex"));
tb.setDepartment(rst.getString("department"));
}
rst.close();
stm.close();
}
catch(Exception e)
{
System.out.println("mei jie guo");
}
Iterator it=list.iterator();
while(it.hasNext())//显示存在问题
{
TeacherBean teab=(TeacherBean)(it.next());
System.out.print(teab.getAccount());//就是这句输出有问题
}
以上是部分代码,本来是应该输出所有的记录,可是结果循环输出了最后一条记录
求大家了,帮帮忙!!谢了!!