1 public static String getRoleIdByRoleName(String[] roles) throws  SQLException{
2   String strRole="aa";
3   DataControl db=new DataControl();
4   for(int i=0;i<roles.length;i++){
5      String sql="select roleId from scopeManage_role where roleName='"+roles[i]+"'";
6      System.out.print(sql);
7      ResultSet rs1=db.getResultSet(sql);
8      System.out.print(rs1.getInt("roleId"));
9   }
10   return strRole;
11 }
错误信息:
java.sql.SQLExcep
tion: [Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the curre
nt cursor position.

解决方案 »

  1.   

    说错了,是从第8行出错的。
    数据库的jar包加载了,通过db.getResultSet(sql)可以执行其他SQL语句。
      

  2.   

    if(rs1.next())
    {
        System.out.println(rs1.getInt("roleId"));
    }
    好象是这样吧?
      

  3.   

    没有写指针下移。
    rs1.next()
      

  4.   

    while(rs1.next){
         System.out.println(rs1.getInt("roleId"));
    }
      

  5.   

    楼上正解!但是写错了:
    while(rs1.next()){
         System.out.println(rs1.getInt("roleId"));
    }
      

  6.   

    你们说的都很对,主要原因就是 使用ResultSet 这个类 必须 使用 while(.... next()) {}  来遍历这个 结果集,  ResultSet 只能这么用, 不象 其他集合类那么灵活. 每次.next()  结果集的游标都会下移
      

  7.   

    ResultSet 这个类 除了可以使用 while(.... next()) {}  来遍历这个结果集外,还可以用其它的几个循环语句来遍历(比如说for() if()……)。