帮忙看看为什么从第7行开始出错?
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.
------解决方案--------------------if(rs1.next())
{
System.out.println(rs1.getInt( "roleId "));
}
好象是这样吧?
------解决方案--------------------while(rs1.next){
System.out.println(rs1.getInt( "roleId "));
}
------解决方案--------------------楼上正解!但是写错了:
while(rs1.next()){
System.out.println(rs1.getInt( "roleId "));
}
------解决方案--------------------你们说的都很对,主要原因就是 使用ResultSet 这个类 必须 使用 while(.... next()) {} 来遍历这个 结果集, ResultSet 只能这么用, 不象 其他集合类那么灵活. 每次.next() 结果集的游标都会下移