package cbf.bean.student.DAOImpl;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import cbf.bean.student.DAO.InfroDAO;
import cbf.bean.student.DAO.SumDAO;
import cbf.bean.student.DBConect.JdbcConnect;
import cbf.bean.student.vo.Infro;
import cbf.bean.student.vo.Sum;
public class StudentDAOImpl implements InfroDAO, SumDAO
{
public List<Sum> querySumByAll() throws Exception
{
String sql = null;//sql语句
PreparedStatement pst = null;
JdbcConnect jdbc = null;
ResultSet rs = null;
List<Sum> all = new ArrayList<Sum>();
Sum sum = null;
sql = "SELECT zNum,sNum,scor FROM sum ";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
rs = pst.executeQuery();
while ( rs.next() )
{
sum = new Sum();
sum.setScor((Integer) rs.getInt("scor"));
sum.setSNum((String) rs.getString("sNum"));
sum.setZNum((String) rs.getString("zNum"));
all.add(sum);
}
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
Collections.sort(all);
return all;
}
public void insertInfro(Sum sum) throws Exception
{
// TODO Auto-generated method stub
JdbcConnect jdbc = null;//声明一个连接
PreparedStatement pst = null;//声明一个数据库操作对象
String sql = "insert into sum (zNum,sNum,sName,scor) values(?,?,?,?)";
Infro infro = new Infro();
infro.setZNum(sum.getZNum());
infro.setSNum(sum.getSNum());
queryInfroByNum(infro);
int temp = infro.getChemi() + infro.getChinese() + infro.getEnglish()
+ infro.getMath();
if (isExist(infro, temp) == 0)
{
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, sum.getZNum());
pst.setString(2, sum.getSNum());
pst.setString(3, infro.getSName());
pst.setInt(4, temp);
pst.executeUpdate();
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
}
else if(isExist(infro, temp) == 1)
{
updateSum(temp,infro);
}
}
private void updateSum(int temp,Infro infro)
{
JdbcConnect jdbc = null;//声明一个连接
PreparedStatement pst = null;//声明一个数据库操作对象
String sql = "update sum set scor=? where sNum=? and zNum=?";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setInt(1, temp);
pst.setString(2, infro.getSNum());
pst.setString(3, infro.getZNum());
pst.executeUpdate();
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
}
private int isExist(Infro infro, int temp)
{
String sql = null;//sql语句
PreparedStatement pst = null;
JdbcConnect jdbc = null;
ResultSet rs = null;
int flage = 0;
sql = "SELECT scor FROM sum WHERE zNum=? and sNum=?";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, infro.getZNum());
pst.setString(2, infro.getSNum());
rs = pst.executeQuery();
if (rs.next())
{
int temp1 = (Integer) rs.getInt("scor");
if (temp1 == temp)
{
flage = 2;
}
else
{
flage = 1;
}
}
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
return flage;
}
//返回总分
public int queryByNum(String zNum, String sNum) throws Exception
{
String sql = null;//sql语句
PreparedStatement pst = null;
JdbcConnect jdbc = null;
ResultSet rs = null;
int scor = 0;
sql = "SELECT scor FROM sum WHERE zNum=? and sNum=?";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, zNum);
pst.setString(2, sNum);
rs = pst.executeQuery();
if (rs.next())
{
scor = (Integer) rs.getInt("scor");
}
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
return scor;
}
public void insertInfro(Infro infro) throws Exception
{
// TODO Auto-generated method stub
JdbcConnect jdbc = null;//声明一个连接
PreparedStatement pst = null;//声明一个数据库操作对象
// 判断是否被录取
if (isPass(infro))
{
infro.setEnroll(1);
}
else
{
infro.setEnroll(0);
}
String sql = "insert into Infro (zNum,sNum,sName,chinese,math,english,chemi,enroll) values(?,?,?,?,?,?,?,?)";//编写sql语句
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, infro.getZNum());
pst.setString(2, infro.getSNum());
pst.setString(3, infro.getSName());
pst.setInt(4, infro.getChinese());
pst.setInt(5, infro.getMath());
pst.setInt(6, infro.getEnglish());
pst.setInt(7, infro.getChemi());
pst.setInt(8, infro.getEnroll());
pst.executeUpdate();
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
}
private boolean isPass(Infro infro)
{
boolean flage = false;
int t1 = infro.getChinese();
int t2 = infro.getChemi();
int t3 = infro.getEnglish();
int t4 = infro.getMath();
int sum = t1 + t2 + t3 + t4;
if ((t1 >= 60) && (t2 >= 60) && (t3 >= 60) && (t4 >= 60))
{
flage = true;
}
else if (sum >= 240)
{
if ((t1 >= 50 && t1 < 60) && (t2 >= 60) && (t3 >= 60) && (t4 >= 60))
{
flage = true;
}
else if ((t2 >= 50 && t2 < 60) && (t1 >= 60) && (t3 >= 60)
&& (t4 >= 60))
{
flage = true;
}
else if ((t3 >= 50 && t3 < 60) && (t2 >= 60) && (t1 >= 60)
&& (t4 >= 60))
{
flage = true;
}
else if ((t4 >= 50 && t4 < 60) && (t2 >= 60) && (t3 >= 60)
&& (t1 >= 60))
{
flage = true;
}
}
return flage;
}
public void queryInfroByNum(Infro infro) throws Exception
{
String sql = null;//sql语句
PreparedStatement pst = null;
JdbcConnect jdbc = null;
ResultSet rs = null;
sql = "SELECT sName,chinese,math,english,chemi,enroll FROM Infro WHERE zNum=? and sNum=?";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, infro.getZNum());
pst.setString(2, infro.getSNum());
rs = pst.executeQuery();
if (rs.next())
{
infro.setSName((String) rs.getString("sName"));
infro.setChinese((Integer) rs.getInt("chinese"));
infro.setMath((Integer) rs.getInt("math"));
infro.setEnglish((Integer) rs.getInt("english"));
infro.setChemi((Integer) rs.getInt("chemi"));
infro.setEnroll((Integer) rs.getInt("enroll"));
}
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
}
public void updateInfro(Infro infro) throws Exception
{
// TODO Auto-generated method stub
JdbcConnect jdbc = null;//声明一个连接
PreparedStatement pst = null;//声明一个数据库操作对象
String sql = "update Infro set sName=?,chinese=?,math=?,english=?,chemi=? where sNum=? and zNum=?";
try
{
jdbc = new JdbcConnect();
pst = jdbc.getConnection().prepareStatement(sql);
pst.setString(1, infro.getSName());
pst.setInt(2, infro.getChinese());
pst.setInt(3, infro.getMath());
pst.setInt(4, infro.getEnglish());
pst.setInt(5, infro.getChemi());
pst.setString(6, infro.getSNum());
pst.setString(7, infro.getZNum());
pst.executeUpdate();
pst.close();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
jdbc.close();
}
}
public List<Infro> queryInfroByAll() throws Exception
{
String sql = null;//sql语句
PreparedStatement pst = null;
JdbcConnect jdbc = null;
ResultSet rs = null;
Infr
没有合适的资源?快使用搜索试试~ 我知道了~
新生录取管理软件(JAva)
共46个文件
jsp:15个
class:10个
java:10个
3星 · 超过75%的资源 需积分: 9 23 下载量 83 浏览量
2009-07-11
16:57:30
上传
评论 6
收藏 158KB RAR 举报
温馨提示
4、新生录取管理软件 任务 :某校录取新生的标准下限为:六门课均及格,或虽有一门课不及格但在50分以上且平均成绩达到60分以上。 要求: (1)从键盘输入每个考生的准考证号、姓名、身份证号、各科成绩,生成一个文件。 (2)可以对考生记录进行添加、修改但不得删除。 (3)找出符合录取标准的考生记录,计算该生总分,生成另一个文件。 (4)打印符合录取标准的考生报表。报表按总分依次从大到小排序,表格内容包括准考证号、姓名、总分、各单科成绩。 设置管理员和普通用户两种登录系统身份,每个用户应有自己的口令; 管理员身份可以完成上述基本要求的功能,普通用户可以通过同时输入准考证号和身份证号查询个人成绩。
资源推荐
资源详情
资源评论
收起资源包目录
student.rar (46个子文件)
student
right.html 174B
find.jsp 3KB
change_into_do.jsp 826B
index.jsp 4KB
enroll_do.jsp 614B
Ouser.jsp 4KB
DataBase
student.mdb 580KB
change.jsp 1KB
regester.jsp 3KB
list.jsp 3KB
enroll.jsp 3KB
loginout.jsp 676B
images
bj.gif 61B
huawenbg_55.gif 3KB
tishi.jpg 26KB
tiao1.jpg 12KB
water.gif 105KB
bg.jpg 850B
hydl_01.gif 105B
change_into.jsp 2KB
left.html 1KB
JavaBean
cbf
bean
student
DAO
SumDAO.java 295B
SumDAO.class 411B
InfroDAO.class 416B
InfroDAO.java 457B
UserDAO.java 179B
UserDAO.class 214B
DAOImpl
UserDAOImpl.class 2KB
StudentDAOImpl.class 8KB
StudentDAOImpl.java 9KB
UserDAOImpl.java 1KB
DBConect
JdbcConnect.java 967B
JdbcConnect.class 1KB
vo
Infro.java 1KB
User.class 906B
Sum.java 720B
User.java 498B
Infro.class 2KB
Sum.class 1KB
factory
DAOFactory.java 375B
DAOFactory.class 652B
loginConf.jsp 1011B
record.jsp 2KB
top.html 814B
Auser.jsp 549B
record_do.jsp 705B
共 46 条
- 1
资源评论
- xiguandengdaige2014-12-18还不错 写论文可以
movingbaby
- 粉丝: 27
- 资源: 15
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功