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,数据库里明明有数据的......
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,数据库里明明有数据的......
from t_user_skill as us, t_skill_info as si, t_chapter_info as ci。
用了别名。没有as,怎么识别
select us.UserSkillValue, si.SkillValue, ci.SkillName from t_user_skill us, t_skill_info si, t_chapter_info ci
语句能正常执行??表名有起别名,那查询的时候怎么不加别名,不加能识别????