package bit.jeffy.service;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Iterator;
import java.util.List;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.StatementCallback;
import bit.jeffy.entity.Student;
import bit.jeffy.springdb.StudentRowMapper;
public class StudentDao{
private JdbcTemplate jdbcTemplate;
private SelectCourseDao selectcoursedao;
private String sql = "select count(*) from Student where XH=?";
private String sql_1 = "insert into Student(id,XH,PASSWORD,XM,YX,MAJOR) values(?,?,?,?,?,?)";
private String sql_2 = "delete from Student where ID=?";
private String sql_4 = "select * from Student where XH=? and PASSWORD=?";
private String sql_5 = "select * from Student where XH=?";
private String sql_6 = "select * from Student";
private String sql_7="select max(id) from student";
//学生登录验证
public boolean validate(Student stu){
String xh = stu.getXh();
if( xh.equals("") || xh==null){
return false;
}
Object[] ob = new Object[]{xh};
int nCount = 0;
nCount = jdbcTemplate.queryForInt(sql,ob);
if( nCount>0 ){
return true;
}else{
return false;
}
}
//管理员增加学生
public boolean add(Student stu){
System.out.println(stu.getId());
String xh = stu.getXh();
String pd = stu.getPassword();
String yx = stu.getYx();
if( xh.equals("") || xh==null || pd.equals("") || pd==null || yx.equals("") || yx==null){
return false;
}
Object ob[] = new Object[]{stu.getId(),xh,pd,stu.getXm()+"",yx,stu.getMajor()+""};
try{
jdbcTemplate.update(sql_1,ob);
return true;
}catch(Exception e){
System.out.println(e.getMessage());
return false;
}
}
//管理员删除学生
public boolean removeById(Student stu){
long id = stu.getId();
if(id < 0){
return false;
}
Object[] ob = new Object[]{new Long(id)};
try{
if(selectcoursedao.deleteAllByStu(stu)){
jdbcTemplate.update(sql_2,ob);
}else{
return false;
}
}catch(Exception e){
return false;
}
return true;
}
//通过学号和密码读出这个用户来
public Student read(Student stu){
System.out.println("run---------------");
String xh = stu.getXh();
String pd = stu.getPassword();
Student st = null;
if( xh.equals("") || xh==null || pd.equals("") || pd==null){
return null;
}
List list = null;
Iterator it = null;
Object[] ob = new Object[]{xh,pd};
try{
RowMapper rm=new StudentRowMapper();
list=jdbcTemplate.query(sql_4,ob,rm);
//list = jdbcTemplate.query(sql_4,ob,new RowMapperResultReader(new StudentRowMapper()));
it = list.iterator();
if( it.hasNext() ){
st = (Student)it.next();
return st;
}else{
return null;
}
}catch(Exception e){
System.out.println(e.getMessage());
return null;
}
}
//用学号取出学生对象,被SelectCourseDao的LogScore调用
public Student readByXh(Student stu){
String xh = stu.getXh();
Student st = null;
if(xh.equals("") || xh==null){
return null;
}
List list = null;
Iterator it = null;
Object[] ob = new Object[]{xh};
try{
RowMapper rm=new StudentRowMapper();
list=jdbcTemplate.query(sql_5,ob,rm);
//list = jdbcTemplate.query(sql_5,ob,new RowMapperResultReader(new StudentRowMapper()));
it = list.iterator();
if( it.hasNext() ){
st = (Student)it.next();
return st;
}else{
return null;
}
}catch(Exception e){
return null;
}
}
//取回所有的学生信息
public List getAll(){
RowMapper rm=new StudentRowMapper();
return jdbcTemplate.query(sql_6,rm);
//return jdbcTemplate.query(sql_6,new RowMapperResultReader(new StudentRowMapper()));
}
/*public Integer getMaxId(){
return (Integer)jdbcTemplate.queryForInt(sql_7)+1;
}*/
public Integer getMaxId(){
return (Integer) jdbcTemplate.execute(new StatementCallback(){
public Object doInStatement(Statement st) throws SQLException,
DataAccessException {
ResultSet rs=st.executeQuery(sql_7);
if(rs.next()){
return rs.getInt(1)+1;
}
else return null;
}});
}
public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
public SelectCourseDao getSelectcoursedao() {
return selectcoursedao;
}
public void setSelectcoursedao(SelectCourseDao selectcoursedao) {
this.selectcoursedao = selectcoursedao;
}
public static void main(String args[]){
ApplicationContext ac=new ClassPathXmlApplicationContext("/bit/jeffy/config/beans.xml");
StudentDao dao=(StudentDao) ac.getBean("studentdao");
System.out.println(dao.getMaxId());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
网上选课系统sqlserver+jsp
共137个文件
class:42个
java:38个
jsp:15个
5星 · 超过95%的资源 需积分: 10 84 下载量 131 浏览量
2010-05-06
00:38:04
上传
评论
收藏 151KB RAR 举报
温馨提示
网上选课系统sqlserver+jsp,网上选课系统sqlserver+jsp
资源推荐
资源详情
资源评论
收起资源包目录
网上选课系统sqlserver+jsp (137个子文件)
SelectCourseDao.class 6KB
StudentDao.class 6KB
CourseDao.class 5KB
TeacherDao.class 4KB
StudentLogAction.class 4KB
TeacherLogAction.class 4KB
AddStudentAction.class 4KB
AdminLogAction.class 4KB
AddTeacherAction.class 3KB
CreateCourseAction.class 3KB
SelectCourseAction.class 3KB
ReadSelectedCourseForStudent.class 3KB
LogScoreAction.class 3KB
LookupSelectedScore.class 3KB
DeleteSelectedCourseAction.class 3KB
DeleteStudentAction.class 3KB
DeleteCourseAction.class 3KB
ReadCourseForStudent.class 2KB
ReadStudent.class 2KB
AdminDao.class 2KB
ReadCourseForTeacher.class 2KB
NewStudent.class 2KB
Student.class 1KB
NewTeacher.class 1KB
SelectCourse.class 1KB
SelectCourseDao$1.class 1KB
Teacher.class 1KB
StudentDao$1.class 1KB
TeacherDao$1.class 1KB
CourseDao$1.class 1KB
Course.class 1KB
StudentRowMapper.class 1KB
SelectCourseRowMapper.class 1KB
TeacherRowMapper.class 1KB
CourseRowMapper.class 1KB
ScoreBean.class 1008B
AdminRowMapper.class 975B
Admin.class 923B
CourseBean.class 836B
TeacherLoger.class 812B
StudentLoger.class 812B
AdminLoger.class 806B
.classpath 6KB
OSX.css 4KB
struts-config_1_1.dtd 35KB
struts-config_1_2.dtd 34KB
web-app_2_3.dtd 33KB
struts-config_1_0.dtd 18KB
web-app_2_2.dtd 16KB
tiles-config_1_1.dtd 12KB
Entries 2KB
Entries 1KB
Entries 543B
TopLeft.gif 2KB
BottomRight.gif 2KB
TopRight.gif 1KB
BottomLeft.gif 331B
title_head.gif 190B
TopMiddle.gif 141B
Background.gif 128B
BottomMiddle.gif 85B
StudentDao.java 5KB
SelectCourseDao.java 5KB
CourseDao.java 5KB
TeacherDao.java 3KB
AddStudentAction.java 3KB
AddTeacherAction.java 3KB
StudentLogAction.java 3KB
TeacherLogAction.java 3KB
AdminLogAction.java 3KB
CreateCourseAction.java 2KB
SelectCourseAction.java 2KB
ReadSelectedCourseForStudent.java 2KB
LogScoreAction.java 2KB
DeleteStudentAction.java 2KB
LookupSelectedScore.java 2KB
DeleteSelectedCourseAction.java 2KB
DeleteCourseAction.java 2KB
AdminDao.java 1KB
ReadCourseForStudent.java 1KB
ReadStudent.java 1KB
ReadCourseForTeacher.java 1KB
NewStudent.java 1KB
NewTeacher.java 895B
Student.java 835B
SelectCourse.java 819B
Teacher.java 696B
Course.java 691B
ScoreBean.java 614B
SelectCourseRowMapper.java 609B
StudentRowMapper.java 576B
CourseRowMapper.java 551B
CourseBean.java 549B
TeacherRowMapper.java 536B
Admin.java 498B
StudentLoger.java 482B
AdminRowMapper.java 482B
TeacherLoger.java 474B
AdminLoger.java 472B
Title_Back.jpg 324B
共 137 条
- 1
- 2
资源评论
- wojiushilr2014-04-16还不错,可以用,就是比较简单
- qq_281298812015-05-21框架不会用,对于啥也不会的菜鸟有点难。但是很全
guoguohong2012
- 粉丝: 3
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- XILINXFPGA源码Xilinxspratan3xcs100E(VGAPS2)
- XILINXFPGA源码XilinxSPARTAN-3E入门开发板实例
- XILINXFPGA源码XilinxSdramVerilog和VHDL版本文档
- 物联网智能家居方案-基于Nucleo-STM32L073&机智云(大赛作品,文档齐全,可直接运行)(文档加Matlab源码)
- XILINXFPGA源码XilinxISE9.xFPGACPLD设计源码
- 成都市地图含高新区(高新南区,高新西区),天府新区,东部新区虚拟行政区划
- XILINXFPGA源码XilinxEDK设计试验
- XILINXFPGA源码XilinxEDKMicroBlaze内置USB固件程序
- 基于 django 的视频点播后台管理系统源代码+数据库
- 基于Java的网上医院预约挂号系统的设计与实现(部署视频)-kaic.mp4
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功