代码如下:
这是一个用户登陆验证的方法,用的是mysql数据库,其中变量 acno,password,还有info_id是表User中的字段,我想在用户验证成功后取出用户的info_id项
public boolean validate(String acno, String password) {
        try {            String cmd = "select count(*) as number from User where acno='" +
                         acno +
                         "'and password='" + password + "'";
            Statement stat = conn.createStatement();
            ResultSet rs = stat.executeQuery(cmd);
            int i = 0;
            
            while (rs.next()) {
                i = rs.getInt("number");
                temp=rs.getInt("info_id");//问题在这里,报错说找不到info_id项!高手请赐教
                
            }
            if (i > 0) {
                return true;
            } else {                return false;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        } finally {
            DBConnection.close(conn);
        }    }

解决方案 »

  1.   

    String cmd = "select count(*) as number from User where acno='" +
                             acno +
                             "'and password='" + password + "'";好像是没看到.
      

  2.   

    mysql我没用过 但是我用的SQLServer2000
    要是SQL找不到列的时候,通常我都是用查询分析器 查看下 是不是String cmd = "select count(*) as number from User where acno='" +
                             acno +
                             "'and password='" + password + "'";
    这句出错了
      

  3.   

    String cmd = "select count(*) as number from User where acno='" +
                             acno +
                             "'and password='" + password + "'";查询的应该是记录,为什么要加聚合函数count()?可能问题出在这里.