java.sql.SQLException: Column Index out of range, 2 > 1.

case1:由于rs.next()遍历查询结果时,下标是从“1”开始,而不是是从“0”开始,导致出错

case2:public class infoDAO {
public ResultSet rs;
DBManager db=new DBManager();

public List jquery(String sql) throws SQLException{
rs=db.executeQuery(sql);
  infoVO infovo;//对象
  List list=new ArrayList();
 while((rs!=null)&&rs.next()){
 infovo=new infoVO();//注意!!!每次实例化一个infovo存入list中,不然将覆盖前面的数据,只能取出最后一条数据
     infovo.setSno(rs.getString(1));
     infovo.setName(rs.getString(2));
     infovo.setAge(rs.getInt(3));
     infovo.setAddress(rs.getString(4));
     infovo.setMajor(rs.getString(5));
   list.add(infovo);
 } 
return list;
}

在servlet中如下调用出错:

String sql="select name from information where name='"+name+"' and sno='"+password+"'";

 list=(ArrayList) infodao.jquery(sql);//出错位置

原因:只查询符合条件的姓名,而调用的自定义方法是将所有字段都存入定义的对象中。

你可能感兴趣的:(出错)