这里是一个关键方法,问题出在while中v.addElement(createInstance(results));
是不是取了两回?应该不会呀。。while的条件是results.next()不会重复的呀。 public Vector getAll(Connection conn,String whereClause,String additionalTables) throws SQLException{
Statement s=null;
ResultSet results=null;
try {
s=conn.createStatement();
Vector v=new Vector();
//Build the query. The basic query is "select <fields> from table "
String query="SELECT "+getFieldList()+" FROM "+getTableName();//Add the additional tables if needed
if (additionalTables!=null){
query=query+","+additionalTables;
}//Add the where clause if needed
if (whereClause!=null){
query=query+" WHERE "+whereClause;
}//Perform the query
results=s.executeQuery(query);//Create a vector of the results
while(results.next()){
v.addElement(createInstance(results));
}
return v;
}
finally{
if(results!=null){
try{results.close();}catch(Exception ignore){}
}
if(s!=null){
try{s.close();}catch(Exception ignore){}
}
}
}
是不是取了两回?应该不会呀。。while的条件是results.next()不会重复的呀。 public Vector getAll(Connection conn,String whereClause,String additionalTables) throws SQLException{
Statement s=null;
ResultSet results=null;
try {
s=conn.createStatement();
Vector v=new Vector();
//Build the query. The basic query is "select <fields> from table "
String query="SELECT "+getFieldList()+" FROM "+getTableName();//Add the additional tables if needed
if (additionalTables!=null){
query=query+","+additionalTables;
}//Add the where clause if needed
if (whereClause!=null){
query=query+" WHERE "+whereClause;
}//Perform the query
results=s.executeQuery(query);//Create a vector of the results
while(results.next()){
v.addElement(createInstance(results));
}
return v;
}
finally{
if(results!=null){
try{results.close();}catch(Exception ignore){}
}
if(s!=null){
try{s.close();}catch(Exception ignore){}
}
}
}
不过还是给了bsd 5分。