String sql = "select UserSkillValue, SkillValue, SkillName from t_user_skill us, t_skill_info si, t_chapter_info ci" + " where ci.Id=si.ChapterId and us.SkillId=si.Id and us.UserId="+ userId + " and ci.Id=" + chapterId;  这是师兄操作数据库的句子,选择的3个值和后面3张表的位置不是一一对应的,能否这么写呢?我已经找出来世数据库查询出了问题,但是还不清楚具体是哪儿?核心代码:        ResultSet rs = sm.executeQuery(sql);
            if(rs != null) {
                while(rs.next()) {
                    map = new HashMap<String, Integer>();
                    map.put("UserSkillValue", rs.getInt("UserSkillValue"));
                    map.put("SkillValue", rs.getInt("SkillValue"));
                    map.put("SkillName", rs.getInt("SkillName"));
                    listUserSkill.add(map);
                }
            }
            else {
                //t_user_skill中没有该用户的该章的技能记录,则全部显示为0
                sql = "select SkillValue, SkillName from t_skill_info si, t_chapter_info ci"
                    + " where ci.Id=si.ChapterId and us.SkillId=si.Id and ci.Id=" + chapterId;
                rs = sm.executeQuery(sql);
                while(rs.next()) {
                    map = new HashMap<String, Integer>();
                    map.put("UserSkillValue", rs.getInt("UserSkillValue"));
                    map.put("SkillValue", rs.getInt("SkillValue"));
                    map.put("SkillName", rs.getInt("SkillName"));
                    listUserSkill.add(map);
                }
            }前提:private List< Map<String, Integer> > listUserSkill;private Map<String, Integer> map; 但是在绘图程序里我用System.out.print(listUserSkill.size());测试输出结果为0,数据库里明明有数据的......

解决方案 »

  1.   

    你设一个断点  断在sql语句那里。然后看一下这个sql语句 的值拷到数据库可视化工具里面执行一下看结果如何。。
      

  2.   

    也就学生写这样的吧  很严重的安全问题严禁拼凑sql... sql脚本在db中试过没有 ?
      

  3.   

    看你的SQL语句比较DT,你还是在数据库里试一下你的语句是否能够得到你要的结果把userId chapterId换成具体的值
      

  4.   

    from t_user_skill us, t_skill_info si, t_chapter_info ci,这个不对吧。改成这样
    from t_user_skill as us, t_skill_info as si, t_chapter_info as ci。
    用了别名。没有as,怎么识别
      

  5.   

    select语句中的列要加表名
    select us.UserSkillValue, si.SkillValue, ci.SkillName from t_user_skill us, t_skill_info si, t_chapter_info ci
      

  6.   

    你的String sql = "select UserSkillValue, SkillValue, SkillName from t_user_skill us, t_skill_info si, t_chapter_info ci" + " where ci.Id=si.ChapterId and us.SkillId=si.Id and us.UserId="+ userId + " and ci.Id=" + chapterId;
    语句能正常执行??表名有起别名,那查询的时候怎么不加别名,不加能识别????
      

  7.   

    弄好了,SQL语句能在navicat里执行没有错误.是另外的原因,谢谢大家了.