package seu.dao;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import seu.domain.CourseSelect;


@Repository
public class CourseSelectDao {

    private JdbcTemplate jdbcTemplate;

    @Autowired
    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public int insertCourseSelect(final CourseSelect courseSelect){
        final String sql = "INSERT INTO CourseSelect(StudentID, CourseID, Grade) VALUES(?,?)";
        Object[] params = new Object[]{courseSelect.getStudentId(),courseSelect.getCourseId(),courseSelect.getGrade()};
        return jdbcTemplate.update(sql,params);
    }
    public int insertCourseSelect(final int studentID, final int courseID,final int grade){
        final String sql = "INSERT INTO CourseSelect(StudentID, CourseID, Grade) VALUES(?,?)";
        Object[] params = new Object[]{studentID,courseID,grade};
        return jdbcTemplate.update(sql,params);
    }
    public int deleteCourseSelectByCourseSelectID(final int courseSelectID){
        final String sql = "DELETE FROM CourseSelect Where CourseSelectID = ?";
        Object[] params = new Object[]{courseSelectID};
        return jdbcTemplate.update(sql,params);
    }

    public int updateStudentIDByCourseSelectID(final int courseSelectID,final int studentID){
        final String sql = "UPDATE CourseSelect SET StudentID = ? WHERE CourseSelectID = ?";
        Object[] params = new Object[]{studentID,courseSelectID};
        return jdbcTemplate.update(sql,params);
    }
    public int updateTeacherIDByCourseSelectID(final int courseSelectID,final int teacherID){
        final String sql = "UPDATE CourseSelect SET TeacherID = ? WHERE CourseSelectID = ?";
        Object[] params = new Object[]{teacherID,courseSelectID};
        return jdbcTemplate.update(sql,params);
    }
    public int updateGradeByCourseSelectID(final int courseSelectID,final int grade){
        final String sql = "UPDATE CourseSelect SET Grade = ? WHERE CourseSelectID = ?";
        Object[] params = new Object[]{grade,courseSelectID};
        return jdbcTemplate.update(sql,params);
    }
    public int queryStudentIDByCourseSelectID(final int courseSelectID){
        final String sql = "SELECT StudentID FROM CourseSelect WHERE CourseSelectID = ?";
        Object[] params = new Object[]{courseSelectID};
        return jdbcTemplate.queryForObject(sql,params,int.class);
    }
    public int queryGradeByCourseSelectID(final int courseSelectID){
        final String sql = "SELECT Grade FROM CourseSelect WHERE CourseSelectID = ?";
        Object[] params = new Object[]{courseSelectID};
        return jdbcTemplate.queryForObject(sql,params,int.class);
    }
    public int queryTeacherIDByCourseSelectID(final int courseSelectID){
        final String sql = "SELECT TeacherID FROM CourseSelect WHERE CourseSelectID = ?";
        Object[] params = new Object[]{courseSelectID};
        return jdbcTemplate.queryForObject(sql,params,int.class);
    }
}

@@ -126,16 +126,64 @@
 mplate;%0A
+import org.springframework.jdbc.core.RowMapper;%0A
 import o
@@ -257,16 +257,97 @@
 elect;%0A%0A
+import java.sql.ResultSet;%0Aimport java.sql.SQLException;%0Aimport java.util.List;%0A%0A
 %0A@Reposi
@@ -3230,10 +3230,613 @@
 ;%0A    %7D%0A
+    public List%3CCourseSelect%3E queryAll() %7B%0A        final String sql = %22SELECT * FROM CourseSelect%22;%0A        return jdbcTemplate.query(sql, new CourseSelectMapper());%0A    %7D%0A    private static final class CourseSelectMapper implements RowMapper%3CCourseSelect%3E %7B%0A        @Override%0A        public CourseSelect mapRow(ResultSet rs, int rowNum) throws SQLException %7B%0A            return new CourseSelect(%0A                    rs.getInt(%22CourseSelectID%22),%0A                    rs.getInt(%22StudentID%22),%0A                    rs.getInt(%22CourseID%22),%0A                    rs.getInt(%22Grade%22)%0A            );%0A        %7D%0A    %7D%0A
 %7D%0A

add courseSelect queryall