package com.student.dao;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
import javax.xml.ws.Response;
import com.student.util.DbConnect;
import com.student.vo.Student;
public class StudentDao implements IstudentDao{
protected static final String FIELDS_INSERT = "id,name,sex,age,weight,hight";
// protected static final String FIELDS_RETURN ="id, " + FIELDS_INSERT;
protected static String INSERT_SQL = "insert into stu_info (" + FIELDS_INSERT + ")" + "values (?,?,?,?,?,?)";
protected static String SELECT_SQL = "select " + FIELDS_INSERT + " from stu_info where id=?";
protected static String UPDATE_SQL = "update stu_info set id=?,name=?,sex=?,age=?,weight=?,hight=? where id=?";
protected static String DELETE_SQL = "delete from stu_info where id=?";
@Override
public int add(Student stu) {
Connection con = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int n = 0;
try {
con = DbConnect.getDBconnection();
prepStmt = con.prepareStatement(INSERT_SQL);
prepStmt.setInt(1,stu.getId());
prepStmt.setString(2, stu.getName());
prepStmt.setString(3, stu.getSex());
prepStmt.setInt(4, stu.getAge());
prepStmt.setFloat(5, stu.getWeight());
prepStmt.setFloat(6, stu.getHight());
n = prepStmt.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
DbConnect.closeDB(con, prepStmt, rs);
}
return n;
}
@Override
public List<Student> findall() {
Connection con = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
List<Student> list = new ArrayList<Student>();
con = DbConnect.getDBconnection();
try {
prepStmt = con.prepareStatement("select * from stu_info");
rs = prepStmt.executeQuery();
while (rs.next()) {
Student stu2 = new Student();
stu2.setId(rs.getInt(1));
stu2.setName(rs.getString(2));
stu2.setSex(rs.getString(3));
stu2.setAge(rs.getInt(4));
stu2.setWeight(rs.getFloat(5));
stu2.setHight(rs.getFloat(6));
list.add(stu2);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DbConnect.closeDB(con, prepStmt, rs);
return list;
}
public int deleted(int id)
{
Connection con = null;
Statement prepStmt = null;
int rs=0 ;
con = DbConnect.getDBconnection();
try {
prepStmt = con.createStatement();
rs=prepStmt.executeUpdate("delete from stu_info where id="+id);
} catch (Exception e) {
// TODO: handle exception
}
return rs;
}
public List<Student> find(int id) {
Connection con = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
List<Student> list = new ArrayList<Student>();
con = DbConnect.getDBconnection();
try {
prepStmt = con.prepareStatement(SELECT_SQL);
prepStmt.setInt(1, id);
rs = prepStmt.executeQuery();
while (rs.next()) {
Student stu2 = new Student();
stu2.setId(rs.getInt(1));
stu2.setName(rs.getString(2));
stu2.setSex(rs.getString(3));
stu2.setAge(rs.getInt(4));
stu2.setWeight(rs.getFloat(5));
stu2.setHight(rs.getFloat(6));
list.add(stu2);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
DbConnect.closeDB(con, prepStmt, rs);
return list;
}
public int update(Student stu) {
Connection con = null;
PreparedStatement prepStmt = null;
ResultSet rs = null;
int n = 0;
try {
con = DbConnect.getDBconnection();
prepStmt = con.prepareStatement(UPDATE_SQL);
prepStmt.setInt(1,stu.getId());
prepStmt.setString(2, stu.getName());
prepStmt.setString(3, stu.getSex());
prepStmt.setInt(4, stu.getAge());
prepStmt.setFloat(5, stu.getWeight());
prepStmt.setFloat(6, stu.getHight());
prepStmt.setInt(7,stu.getId());
n = prepStmt.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
DbConnect.closeDB(con, prepStmt, rs);
}
return n;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
学生体质健康管理系统源码+项目说明.zip
共32个文件
java:9个
class:9个
jpg:3个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 125 浏览量
2024-03-05
16:31:32
上传
评论
收藏 852KB ZIP 举报
温馨提示
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip学生体质健康管理系统源码+项目说明.zip 学生体质健康管理系统源码+项目说明.zip
资源推荐
资源详情
资源评论
收起资源包目录
学生体质健康管理系统源码+项目说明.zip (32个子文件)
code_20105
.classpath 825B
.settings
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.jdt.core.prefs 357B
.jsdtscope 555B
org.eclipse.wst.common.component 453B
org.eclipse.wst.common.project.facet.core.xml 335B
org.eclipse.wst.jsdt.ui.superType.container 49B
src
com
student
servlet
AddServlet.java 2KB
update.java 2KB
find.java 2KB
FindAllServlet.java 2KB
delet.java 2KB
dao
IstudentDao.java 280B
StudentDao.java 4KB
util
DbConnect.java 1KB
vo
Student.java 787B
build
classes
com
student
servlet
AddServlet.class 2KB
FindAllServlet.class 2KB
delet.class 2KB
update.class 2KB
find.class 2KB
dao
IstudentDao.class 404B
StudentDao.class 5KB
util
DbConnect.class 2KB
vo
Student.class 1KB
WebContent
WEB-INF
lib
mysql-connector-java-5.1.13-bin.jar 750KB
web.xml 638B
image
3.JPG 2KB
6.jpg 45KB
1.jpg 70KB
META-INF
MANIFEST.MF 36B
.project 872B
共 32 条
- 1
资源评论
土豆片片
- 粉丝: 1540
- 资源: 5641
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功