📄 compulsoryscoredao.java
字号:
package dao;
import java.sql.*;
import conn.ConnectDB;
import java.util.*;
import vo.CompulsoryScoreVO;
public class CompulsoryScoreDAO
{
public CompulsoryScoreDAO()
{
}
public boolean checkScore(String student_id,String term,String course_id)
{
boolean isexist=false;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where student_id='"+student_id+"'and term='"+term+"'and course_id='"+course_id+"'");
if(rs.next())
{
isexist=true;
}
else
isexist=false;
}
catch(Exception e)
{
e.printStackTrace();
}
return isexist;
}
public boolean checkStudent(String student_id)
{
boolean isexist=false;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where student_id='"+student_id+"'");
if(rs.next())
{
isexist=true;
}
else
isexist=false;
}
catch(Exception e)
{
e.printStackTrace();
}
return isexist;
}
/*public boolean checkClass(String class_id)
{
boolean isexist=false;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where class_id='"+class_id+"'");
if(rs.next())
{
isexist=true;
}
else
isexist=false;
}
catch(Exception e)
{
e.printStackTrace();
}
return isexist;
}*/
public CompulsoryScoreVO getScoreByStudentId(String student_id,String term,String course_id)
{
CompulsoryScoreVO scorevo=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where student_id='"+student_id+"'and term='"+term+"'and course_id='"+course_id+"'");
if(rs.next())
{
scorevo=new CompulsoryScoreVO();
scorevo.setStudentId(rs.getString("student_id"));
scorevo.setClassId(rs.getString("class_id"));
scorevo.setCourseId(rs.getString("course_id"));
scorevo.setExamtime(rs.getString("datetimes"));
scorevo.setScore(rs.getString("score"));
scorevo.setTerm(rs.getString("term"));
scorevo.setNote(rs.getString("note"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
return scorevo;
}
public ArrayList getScoresByStudentId(String student_id,String term)
{
ArrayList scores=new ArrayList();
CompulsoryScoreVO scorevo=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where student_id='"+student_id+"'and term='"+term+"'");
while(rs.next())
{
scorevo=new CompulsoryScoreVO();
scorevo.setStudentId(rs.getString("student_id"));
scorevo.setClassId(rs.getString("class_id"));
scorevo.setCourseId(rs.getString("course_id"));
scorevo.setExamtime(rs.getString("datetimes"));
scorevo.setScore(rs.getString("score"));
scorevo.setTerm(rs.getString("term"));
scorevo.setNote(rs.getString("note"));
scores.add(scorevo);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return scores;
}
public ArrayList getScoresByClassId(String class_id,String term)
{
ArrayList scores=new ArrayList();
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from compulsory_score where class_id='"+class_id+"'and term='"+term+"'");
while(rs.next())
{
CompulsoryScoreVO scorevo=new CompulsoryScoreVO();
scorevo.setStudentId(rs.getString("student_id").trim());
scorevo.setClassId(rs.getString("class_id").trim());
scorevo.setCourseId(rs.getString("course_id").trim());
scorevo.setExamtime(rs.getString("datetimes").trim());
scorevo.setScore(rs.getString("score").trim());
scorevo.setTerm(rs.getString("term").trim());
scorevo.setNote(rs.getString("note").trim());
scores.add(scorevo);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return scores;
}
public void insertScore(CompulsoryScoreVO scorevo)
{
try
{
ConnectDB.executeUpdate("insert into compulsory_score values('"+scorevo.getStudentId()+"','"+scorevo.getCourseId()+"','"+scorevo.getTerm()+"','"+scorevo.getScore()+"','"+scorevo.getExamtime()+"','"+scorevo.getClassId()+"','"+scorevo.getNote()+"')");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void alterScore(CompulsoryScoreVO scorevo)
{
ResultSet rs=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
rs=stat.executeQuery("select * from compulsory_score where student_id='"+scorevo.getStudentId()+"'and class_id='"+scorevo.getClassId()+"'and term='"+scorevo.getTerm()+"'and course_id='"+scorevo.getCourseId()+"'");
if(rs.next())
{
ConnectDB.executeUpdate("update compulsory_score set score='"+scorevo.getScore()+"',datetimes='"+scorevo.getExamtime()+"',note='"+scorevo.getNote()+"'where student_id='"+scorevo.getStudentId()+"'and class_id='"+scorevo.getClassId()+"'and term='"+scorevo.getTerm()+"'and course_id='"+scorevo.getCourseId()+"'");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void deleteScore(String student_id,String class_id,String term,String course_id)
{
ResultSet rs=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
rs=stat.executeQuery("select * from compulsory_score where student_id='"+student_id+"'and class_id='"+class_id+"'and term='"+term+"'and course_id='"+course_id+"'");
if(rs.next())
{
ConnectDB.executeUpdate("delete from compulsory_score where student_id='"+student_id+"'and class_id='"+class_id+"'and term='"+term+"'and course_id='"+course_id+"'");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -