📄 optionalscoredao.java
字号:
package dao;
import java.sql.*;
import conn.ConnectDB;
import java.util.*;
import vo.OptionalScoreVO;
public class OptionalScoreDAO
{
public OptionalScoreDAO()
{
}
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 optional_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 optional_score where student_id='"+student_id+"'");
if(rs.next())
{
isexist=true;
}
else
isexist=false;
}
catch(Exception e)
{
e.printStackTrace();
}
return isexist;
}
public OptionalScoreVO getScoreByStudentId(String student_id,String term,String course_id)
{
OptionalScoreVO scorevo=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from optional_score where student_id='"+student_id+"'and term='"+term+"'and course_id='"+course_id+"'");
if(rs.next())
{
scorevo=new OptionalScoreVO();
scorevo.setStudentId(rs.getString("student_id"));
scorevo.setCourseId(rs.getString("course_id"));
scorevo.setExamtime(rs.getString("datetimes"));
scorevo.setGrade(rs.getString("grade"));
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();
OptionalScoreVO scorevo=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery("select * from optional_score where student_id='"+student_id+"'and term='"+term+"'");
while(rs.next())
{
scorevo=new OptionalScoreVO();
scorevo.setStudentId(rs.getString("student_id"));
scorevo.setCourseId(rs.getString("course_id"));
scorevo.setExamtime(rs.getString("datetimes"));
scorevo.setGrade(rs.getString("grade"));
scorevo.setTerm(rs.getString("term"));
scorevo.setNote(rs.getString("note"));
scores.add(scorevo);
}
}
catch(Exception e)
{
e.printStackTrace();
}
return scores;
}
public void insertScore(OptionalScoreVO scorevo)
{
try
{
ConnectDB.executeUpdate("insert into optional_score values('"+scorevo.getStudentId()+"','"+scorevo.getCourseId()+"','"+scorevo.getTerm()+"','"+scorevo.getGrade()+"','"+scorevo.getNote()+"','"+scorevo.getExamtime()+"')");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void alterScore(OptionalScoreVO scorevo)
{
ResultSet rs=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
rs=stat.executeQuery("select * from optional_score where student_id='"+scorevo.getStudentId()+"'and term='"+scorevo.getTerm()+"'and course_id='"+scorevo.getCourseId()+"'");
if(rs.next())
{
ConnectDB.executeUpdate("update optional_score set score='"+scorevo.getGrade()+"',datetimes='"+scorevo.getExamtime()+"',note='"+scorevo.getNote()+"'where student_id='"+scorevo.getStudentId()+"'and term='"+scorevo.getTerm()+"'and course_id='"+scorevo.getCourseId()+"'");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void deleteScore(String student_id,String term,String course_id)
{
ResultSet rs=null;
try
{
Connection conn=ConnectDB.getConnection();
Statement stat=conn.createStatement();
rs=stat.executeQuery("select * from optional_score where student_id='"+student_id+"'and term='"+term+"'and course_id='"+course_id+"'");
if(rs.next())
{
ConnectDB.executeUpdate("delete from optional_score where student_id='"+student_id+"'and term='"+term+"'and course_id='"+course_id+"'");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -