package com.dao;
import com.dao.impl.InpatientDaoImpl;
import com.entity.Inpatient;
import com.util.JdbcUtil;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;
/**
* @author 买热孜亚
*/
public class InpatientDao implements InpatientDaoImpl {
/*
* 根据已知patient_id查询患者信息
* @throws SQLException
*/
@Override
public Inpatient findByWardId(Integer ward_id) throws SQLException {
String sql = "SELECT ward_id,p_name,bed_id,cost,indated FROM IPD WHERE ward_id=?";
Inpatient ipd = null;
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, ward_id);
ResultSet rs = pstmt.executeQuery();
if(rs.next()) {
ipd = new Inpatient();
ipd.setWard_id(rs.getInt("ward_id"));
ipd.setP_name(rs.getString("p_name"));
ipd.setBed_id(rs.getString("bed_id"));
ipd.setCost(rs.getString("cost"));
ipd.setIndated(rs.getTimestamp("indated"));
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
}finally {
JdbcUtil.close(conn);
}
return ipd;
}
/*
* 根据账号的创建时间排序查询
* @throws SQLException
*/
@Override
public List<Inpatient> findAll() throws SQLException{
List<Inpatient> list = new ArrayList<>();
String sql = "SELECT ward_id,p_name,bed_id,cost,indated FROM IPD ORDER BY indated DESC";
Connection conn =null;
try {
conn = JdbcUtil.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
Inpatient ipd=new Inpatient();
ipd.setWard_id(rs.getInt("ward_id"));
ipd.setP_name(rs.getString("p_name"));
ipd.setBed_id(rs.getString("bed_id"));
ipd.setCost(rs.getString("cost"));
ipd.setIndated(rs.getTimestamp("indated"));
list.add(ipd);
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
}finally{
JdbcUtil.close(conn);
}
return list;
}
/*
* 分页查询
* @throws SQLException
*/
@Override
public List<Inpatient> findByPage(int page, int perPage) throws SQLException{
List<Inpatient> list = new ArrayList<>();
String sql = "SELECT ward_id,p_name,bed_id,cost,indated FROM IPD LIMIT ?,?";
Connection conn =null;
try {
conn = JdbcUtil.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
int begin = (page-1)*perPage;
pstmt.setInt(1, begin);
pstmt.setInt(2, perPage);
ResultSet rs = pstmt.executeQuery();
while(rs.next()) {
Inpatient ipd=new Inpatient();
ipd.setWard_id(rs.getInt("ward_id"));
ipd.setP_name(rs.getString("p_name"));
ipd.setBed_id(rs.getString("bed_id"));
ipd.setCost(rs.getString("cost"));
ipd.setIndated(rs.getTimestamp("indated"));
list.add(ipd);
}
} catch (SQLException e) {
e.printStackTrace();
throw e;
}finally{
JdbcUtil.close(conn);
}
return list;
}
@Override
public int findMaxPage(int perPage) throws SQLException{
int maxPage = 0;
String sql = "SELECT COUNT(ward_id) FROM IPD";
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
rs.next();
int recoreds = rs.getInt(1);
maxPage = recoreds % perPage == 0 ? recoreds / perPage : recoreds / perPage + 1;
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
JdbcUtil.close(conn);
}
return maxPage;
}
/*
* 删除账号
* @throws SQLException
*/
@Override
public void delete(Integer ward_id) throws SQLException {
String sql = "DELETE FROM IPD WHERE ward_id=?";
Connection conn = null;
try {
conn = JdbcUtil.getConnection();
PreparedStatement pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, ward_id);
pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw e;
}finally {
JdbcUtil.close(conn);
}
}
/**
* 保存新增住院患者
* @param inpatient
* @throws SQLException
*/
@Override
public void add(Inpatient inpatient) throws SQLException {
String sql = "INSERT INTO ipd(ward_id, p_name, bed_id, cost, indated) VALUE(DEFAULT,?,?,?,NOW())";
Connection con = null;
PreparedStatement preparedStatement = null;
try {
con = JdbcUtil.getConnection();
preparedStatement = con.prepareStatement(sql);
preparedStatement.setString(1,inpatient.getP_name());
preparedStatement.setString(2,inpatient.getBed_id());
preparedStatement.setString(3,inpatient.getCost());
preparedStatement.executeUpdate();
} catch (SQLException e){
// TODO Auto-generated catch block
e.printStackTrace();
throw e;
} finally {
JdbcUtil.close(con);
}
}
/**
* 修改住院患者信息
* @param inpatient
* @throws SQLException
*/
@Override
public void update(Inpatient inpatient) throws SQLException {
String sql ="UPDATE ipd SET p_name=?,bed_id=?,cost=? WHERE ward_id=?";
Connection con = null;
PreparedStatement preparedStatement = null;
try {
con = JdbcUtil.getConnection();
preparedStatement = con.prepareStatement(sql);
preparedStatement.setString(1, inpatient.getP_name());
preparedStatement.setString(2, inpatient.getBed_id());
preparedStatement.setString(3, inpatient.getCost());
preparedStatement.setInt(4, inpatient.getWard_id());
preparedStatement.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
throw e;
} finally {
JdbcUtil.close(con);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 基于javaweb和mysql实现的医疗管理系统源码(课程大作业).zip 1、该资源内项目代码都是经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载使用,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能。
资源推荐
资源详情
资源评论
收起资源包目录
基于javaweb和mysql实现的医疗管理系统源码(课程大作业).zip (437个子文件)
CostDao.class 6KB
CostDao.class 6KB
RegistDao.class 6KB
RegistDao.class 6KB
PatientDao.class 6KB
PatientDao.class 6KB
InpatientDao.class 6KB
InpatientDao.class 6KB
MedicineDao.class 5KB
MedicineDao.class 5KB
StockDao.class 5KB
StockDao.class 5KB
BlogFatherDao.class 4KB
BlogFatherDao.class 4KB
Regist.class 4KB
Regist.class 4KB
AdminDao.class 4KB
AdminDao.class 4KB
DoctorDao.class 3KB
DoctorDao.class 3KB
Stock.class 3KB
Stock.class 3KB
DepartmentDao.class 3KB
DepartmentDao.class 3KB
ScDao.class 3KB
ScDao.class 3KB
Medicine.class 3KB
Medicine.class 3KB
UpdateMedicineServlet.class 3KB
UpdateMedicineServlet.class 3KB
CostUpdateServlet.class 3KB
CostUpdateServlet.class 3KB
AddStockServlet.class 3KB
AddStockServlet.class 3KB
AddMedicineServlet.class 2KB
AddMedicineServlet.class 2KB
CostAddServlet.class 2KB
CostAddServlet.class 2KB
UpdatePatientServlet.class 2KB
UpdatePatientServlet.class 2KB
LoginFilter.class 2KB
LoginFilter.class 2KB
JdbcUtil.class 2KB
JdbcUtil.class 2KB
UpdateRegistServlet.class 2KB
UpdateRegistServlet.class 2KB
Cost.class 2KB
Cost.class 2KB
UpdateInPatientServlet.class 2KB
UpdateInPatientServlet.class 2KB
RegistServlet.class 2KB
RegistServlet.class 2KB
UpdateStockServlet.class 2KB
UpdateStockServlet.class 2KB
ShowUpdateServlet.class 2KB
ShowUpdateServlet.class 2KB
MyListener.class 2KB
MyListener.class 2KB
UpdateBlogServlet.class 2KB
UpdateBlogServlet.class 2KB
Doctor.class 2KB
Doctor.class 2KB
AddDoctorServlet.class 2KB
AddDoctorServlet.class 2KB
FindByCostPageServlet.class 2KB
FindByCostPageServlet.class 2KB
LoginServlet.class 2KB
LoginServlet.class 2KB
FindByPageServlet.class 2KB
FindByPageServlet.class 2KB
AddServlet.class 2KB
AddServlet.class 2KB
FindByInPatientIdServlet.class 2KB
FindByInPatientIdServlet.class 2KB
MtoUpdateServlet.class 2KB
MtoUpdateServlet.class 2KB
ToUpdateCostServlet.class 2KB
ToUpdateCostServlet.class 2KB
AddInPatientServlet.class 2KB
AddInPatientServlet.class 2KB
AddBlogServlet.class 2KB
AddBlogServlet.class 2KB
FindByPatientIdServlet.class 2KB
FindByPatientIdServlet.class 2KB
ToUpdateStockServlet.class 2KB
ToUpdateStockServlet.class 2KB
AddScServlet.class 2KB
AddScServlet.class 2KB
RegisterServlet.class 2KB
RegisterServlet.class 2KB
ToRegistUpdateServlet.class 2KB
ToRegistUpdateServlet.class 2KB
Sc.class 2KB
Sc.class 2KB
ShowBlogServlet.class 2KB
ShowBlogServlet.class 2KB
FindInPatientServlet.class 2KB
FindInPatientServlet.class 2KB
FindAllPatientServlet.class 2KB
FindAllPatientServlet.class 2KB
共 437 条
- 1
- 2
- 3
- 4
- 5
资源评论
Make程序设计
- 粉丝: 7039
- 资源: 3582
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功