返回Vector的错误!! 将ResultSet的结果存放到vector 中,然后返回这个vector。在main中获取这个vector,但是vector中的每一个元素都变成了ResultSet中的最后一条纪录。但在存放过程中检查却是正确的。为什么?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 把你存入vector的那段代码帖出来 在线等 public class manage{ private material temp=new material(); private ResultSet rs=null; public Vector getResult(String semester) { Vector<material> list=new Vector<material>(); try { DBConnect db=new DBConnect(); String sql="Select * from mplans where 学期='"+semester+"'"; rs=db.executeQuery(sql); while(rs.next()) { temp.setClassnum(new String(rs.getString(1).getBytes("ISO8859-1"),"GBK")); temp.setClassname(new String(rs.getString(2).getBytes("ISO8859-1"),"GBK")); temp.setBook(new String(rs.getString(3).getBytes("ISO8859-1"),"GBK")); temp.setAuthor(new String(rs.getString(4).getBytes("ISO8859-1"),"GBK")); temp.setPublisher(new String(rs.getString(5).getBytes("ISO8859-1"),"GBK")); temp.setYear(new String(rs.getString(6).getBytes("ISO8859-1"),"GBK")); temp.setCharge(new String(rs.getString(7).getBytes("ISO8859-1"),"GBK")); temp.setAmount(new String(rs.getString(8).getBytes("ISO8859-1"),"GBK")); temp.setTeachers(new String(rs.getString(9).getBytes("ISO8859-1"),"GBK")); temp.setSemester(new String(rs.getString(10).getBytes("ISO8859-1"),"GBK")); list.add(temp); } rs.close(); db.close(); } catch(Exception e) { System.out.println(e); } return list; } public static void main(String arg[]) { manage f=new manage(); Vector<material> a=new Vector<material>(); a=f.getResult("2005-2005下"); for(int i=0;i<a.size();i++) { material t=(material)a.get(i); } }} 在main中的vector a中所有元素的值都一样了,都是数据库最后一条纪录 private material temp ;while(rs.next()){temp = new material();............list.add(temp);} jsp ENCTYPE= "multipart/form-data " 接收值问题 高分请请教:关于记录合并的问题 做了一个小游戏,eclipse或者JAR比java慢 为什么? windows版本tomcat上调试applet问题 请问我把时间格式后为什么小时和分都变成了0呢 ?比如06/12/22 00:00 swing superset Applet嵌入问题。 关于麻将游戏排列问题 如何让一个Frame始终在最前面,即让它是模态窗体 java中绘制表格问题 java中如何获得当时的时间? 请问可不可以把用JAVA做的软件做成可执行的安装文件?
在线等
{
private material temp=new material();
private ResultSet rs=null;
public Vector getResult(String semester)
{ Vector<material> list=new Vector<material>();
try
{
DBConnect db=new DBConnect();
String sql="Select * from mplans where 学期='"+semester+"'";
rs=db.executeQuery(sql);
while(rs.next())
{
temp.setClassnum(new String(rs.getString(1).getBytes("ISO8859-1"),"GBK"));
temp.setClassname(new String(rs.getString(2).getBytes("ISO8859-1"),"GBK"));
temp.setBook(new String(rs.getString(3).getBytes("ISO8859-1"),"GBK"));
temp.setAuthor(new String(rs.getString(4).getBytes("ISO8859-1"),"GBK"));
temp.setPublisher(new String(rs.getString(5).getBytes("ISO8859-1"),"GBK"));
temp.setYear(new String(rs.getString(6).getBytes("ISO8859-1"),"GBK"));
temp.setCharge(new String(rs.getString(7).getBytes("ISO8859-1"),"GBK"));
temp.setAmount(new String(rs.getString(8).getBytes("ISO8859-1"),"GBK"));
temp.setTeachers(new String(rs.getString(9).getBytes("ISO8859-1"),"GBK"));
temp.setSemester(new String(rs.getString(10).getBytes("ISO8859-1"),"GBK"));
list.add(temp);
}
rs.close();
db.close();
}
catch(Exception e)
{
System.out.println(e);
} return list;
}
public static void main(String arg[])
{
manage f=new manage();
Vector<material> a=new Vector<material>();
a=f.getResult("2005-2005下");
for(int i=0;i<a.size();i++)
{
material t=(material)a.get(i);
}
}
}
while(rs.next())
{
temp = new material();
...
...
...
...list.add(temp);
}