java.sql.SQLException: Column Index out of range, 2 > 1.
2017-03-17 16:47
741 查看
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);//出错位置
原因:只查询符合条件的姓名,而调用的自定义方法是将所有字段都存入定义的对象中。
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);//出错位置
原因:只查询符合条件的姓名,而调用的自定义方法是将所有字段都存入定义的对象中。
相关文章推荐
- FAQ(52):java.sql.SQLException: Column Index out of range, 0 > 13. at com.mysql.jdbc.ResultSet.getInt
- java.sql.SQLException: Column Index out of range, 2 > 1.
- Caused by: java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1
- BIRT出现java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)的问题
- java.sql.SQLException:Column Index out of range,0<1
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
- java.sql.SQLException:Column Index out of range,0<1
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).
- java.sql.SQLException:Column Index out of range,0<1
- java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2).
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
- 未重新服务器而导致的错误java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
- Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0
- 更新数据库表信息时抛异常java.sql.SQLException: Parameter index out of range (1 > number of parameter
- java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0)
- Caused by: java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 2
- 造成原因java.sql.SQLException: Parameter index out of range (3 > number of parameters, which is 0).
- java.sql.SQLException: Parameter index out of range (2 > number of parameters, which is 1).
- 从数据库中读取信息时抛出异常java.sql.SQLException: Parameter index out of range (1 > number of parameter