📄 selectcoursedao.java
字号:
package bit.jeffy.service;
import java.util.List;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapperResultReader;
import bit.jeffy.bean.ScoreBean;
import bit.jeffy.entity.Course;
import bit.jeffy.entity.SelectCourse;
import bit.jeffy.entity.Student;
import bit.jeffy.springdb.SelectCourseRowMapper;
public class SelectCourseDao{
private JdbcTemplate jdbcTemplate;
private CourseDao coursedao;
private StudentDao studentdao;
private String sql_1 = "insert into selectcourse(STUDENT_ID,TEACHER_ID,COURSE_ID) values(?,?,?)";
private String sql_2 = "update selectcourse set SCORE=? where STUDENT_ID=? and TEACHER_ID=? and COURSE_ID=?";
private String sql_3 = "delete from selectcourse where ID=?";
private String sql_4 = "select * from selectcourse where STUDENT_ID=?";
private String sql_5 = "delete from selectcourse where STUDENT_ID=?";
private String sql_6 = "select count(*) from selectcourse where STUDENT_ID=? and TEACHER_ID=? and COURSE_ID=?";
//学生选课
public boolean add(SelectCourse course){
long stu_id = course.getStudent_id();
long tea_id = course.getTeacher_id();
long cou_id = course.getCourse_id();
if( stu_id < 0 || tea_id < 0 || cou_id < 0 ){
return false;
}
Object ob[] = new Object[]{new Long(stu_id),new Long(tea_id),new Long(cou_id)};
try{
jdbcTemplate.update(sql_1,ob);
return true;
}catch(Exception e){
return false;
}
}
//学生删除选课
public boolean remove(SelectCourse course){
long cid = course.getId();
if( cid < 0 ){
return false;
}
Object ob[] = new Object[]{new Long(cid)};
try{
jdbcTemplate.update(sql_3,ob);
return true;
}catch(Exception e){
return false;
}
}
//删除某一个学生的所有选课记录
public boolean deleteAllByStu(Student stu){
long id = stu.getId();
if(id < 0){
return false;
}
Object ob[] = new Object[]{new Long(id)};
try{
jdbcTemplate.update(sql_5,ob);
}catch(Exception e){
return false;
}
return true;
}
//老师登录成绩
public boolean LogScore(ScoreBean sc, long tid){
String xh = sc.getXh();
String course_no = sc.getCourse_no();
int score = sc.getScore();
long sid, cid;
Course c = new Course();
c.setCourse_no(course_no);
Course rtc = coursedao.read(c);
if(rtc == null){
return false;
}
cid = rtc.getId();
Student stu = new Student();
stu.setXh(xh);
Student rtu = studentdao.readByXh(stu);
if(rtu == null){
return false;
}
sid = rtu.getId();
int nCount = 0;
Object[] ob = new Object[]{new Long(sid), new Long(tid), new Long(cid)};
try{
//先判断该选课记录是否存在
nCount = jdbcTemplate.queryForInt(sql_6,ob);
if( nCount < 0){
return false;
}
}catch(Exception e){
return false;
}
Object[] ob_1 = new Object[]{new Integer(score), new Long(sid), new Long(tid), new Long(cid)};
System.out.println(sid+","+tid+","+cid);
try{
jdbcTemplate.update(sql_2,ob_1);
}catch(Exception e){
return false;
}
return true;
}
public List getAll(Student stu){
long stu_id = stu.getId();
if( stu_id < 0 ){
return null;
}
Object[] ob = new Object[]{new Long(stu_id)};
return jdbcTemplate.query(sql_4,ob,new RowMapperResultReader(new SelectCourseRowMapper()));
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public CourseDao getCoursedao() {
return coursedao;
}
public void setCoursedao(CourseDao coursedao) {
this.coursedao = coursedao;
}
public StudentDao getStudentdao() {
return studentdao;
}
public void setStudentdao(StudentDao studentdao) {
this.studentdao = studentdao;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -