日期:2014-05-18  浏览次数:20762 次

mysql数据库中的数据读入到vector中问题,困扰了我好几天了,希望高手帮忙
我数据库中有个表,其中有10条记录,我想把记录取出来放到一个vector中,可是vector中只有最后一条记录,想了好几天了也不明白,请高手帮忙解决
代码如下:
ArticleVo   ar   =   new   ArticleVo();
Vector   vt   =   new   Vector(10);
while   (rs.next()){
ar.setTitle(rs.getString( "title "));
ar.setAuthor(rs.getString( "author "));
ar.setReply(rs.getString( "reply "));
ar.setRegdate(rs.getString( "regdate "));
ar.setPostdate(rs.getString( "postdate "));
vt.addElement(ar);
}

------解决方案--------------------
Vector vt = new Vector(10);
while (rs.next()){
ArticleVo ar = new ArticleVo();
ar.setTitle(rs.getString( "title "));
ar.setAuthor(rs.getString( "author "));
ar.setReply(rs.getString( "reply "));
ar.setRegdate(rs.getString( "regdate "));
ar.setPostdate(rs.getString( "postdate "));
vt.addElement(ar);
}

你的那段代码只是加了一个对象而已。