0

i have 3 tables user(id,name), course(id,name) and users_courses(user_id,course_id,grade)

and i used this query (which works on phpmyadmin) in DbCourse.java

    private final String GET_STUDENT_COURSES = "select * from users_courses where user_id = ? ";

and the method i want to get hashmap with course name and the grade

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;
}

this is the get_course method

 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;
}

and i get this exception when i use it java.sql.SQLException: Column 'grade' not found. please help i dont know where is the error

Guys after i commented the 2 line inside the while loop i get stackoverflow exception what is the reason

0 Answers0