java - java.sql.SQLException:未找到列“等级”
问题描述
我有 3 个表 user(id,name), course(id,name) 和 users_courses(user_id,course_id,grade)
我在 DbCourse.java 中使用了这个查询(适用于 phpmyadmin)
private final String GET_STUDENT_COURSES = "select * from users_courses where user_id = ? ";
以及我想获取带有课程名称和成绩的哈希图的方法
public HashMap<String, Double> getHashMapStudentCourses(User user) {
HashMap<String, Double> studentCourses = new HashMap<>();
try {
ps = con.prepareStatement(GET_STUDENT_COURSES);
ps.setInt(1, user.getId());
rs = ps.executeQuery();
while(rs.next()){
String courseName =(this.get_course(rs.getInt("course_id"))).getCourse_name();
studentCourses.put(courseName,rs.getDouble("grade"));
}
} catch (SQLException ex) {
Logger.getLogger(DbCourse.class.getName()).log(Level.SEVERE, null, ex);
}
return studentCourses;
}
这是 get_course 方法
public Course get_course(int id) {
try {
ps = con.prepareStatement(GET_COURSE);
ps.setInt(1, id);
rs = ps.executeQuery();
if (rs.first()) {
return new Course(rs.getInt("id"), rs.getString("name"));
}
} catch (SQLException ex) {
Logger.getLogger(DbCourse.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
当我使用它时出现此异常 java.sql.SQLException: Column 'grade' not found。请帮助我不知道错误在哪里
伙计们,在我评论了 while 循环中的 2 行之后,我得到了 stackoverflow 异常,这是什么原因
解决方案
推荐阅读
- angular - Angular 模块联盟 BrowserModule
- arrays - 使用 mongo 查询 [版本 < 3.6 ] 更新多级嵌套数组
- python - 如何使用 XLXS 编写器绘制数据框,“值”和“类别”轴中有多个值
- postgresql - AWS Glue - 如何使用物化视图?
- python - 使用 BeautifulSoup 进行网页抓取:获得 ValueError
- javascript - Snowflake UDF 在使用“LIMIT”时表现不同
- javascript - Firebase Auth Google Captcha电话号码验证反应原生
- flutter - Flutter:如何根据屏幕大小缩放文本
- openshift - Openshift 4 中的用户管理
- flutter - 颤动中的共享首选项实例空错误