第八篇

本文详细介绍了医院信息系统的用户模块设计与实现过程,包括患者、医生及管理员的登录注册功能,挂号系统,以及部门和医生信息查询等功能。通过具体代码示例展示了如何使用Java和SQL进行数据库操作,如查询、更新、删除等。

MyHospital08

UserDao.java

package com.chinasofti.hospital.user.dao;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.chinasofti.hospital.user.sql.UserSql;
import com.chinasofti.hospital.user.vo.Department;
import com.chinasofti.hospital.user.vo.Doctor;
import com.chinasofti.hospital.user.vo.GuaHao;
import com.chinasofti.hospital.user.vo.Notice;
import com.chinasofti.hospital.user.vo.Patient;
import com.chinasofti.hospital.util.JDBCDao;
import com.chinasofti.hospital.util.JDBCUtil;
import com.chinasofti.hospital.util.PageHelper;






public class UserDao {

	public boolean findNameDao(String name) {
		// TODO Auto-generated method stub		
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		boolean bn=false;
		String patientName = null;
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.FIND_NAME);
			pstmt.setString(1, name);
			rs = pstmt.executeQuery();
			while(rs.next()){
				patientName = rs.getString(1);
				if (patientName!=null) {
					bn=true;
				} 
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		
		return bn;
	}

	public int registerDao(Patient patient) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.REGISTER);
			pstmt.setString(1, patient.getPATIENT_NAME());
			pstmt.setString(2, patient.getAccount());
			pstmt.setString(3, patient.getUserPwd());
			pstmt.setString(4, patient.getSex());
			pstmt.setString(5, patient.getAge());
			pstmt.setString(6, patient.getTelphone());
			pstmt.setString(7, patient.getMail());
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public String patientLoginDao(String userName) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;	
		String pwd = null;
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.PATIENT_LOGIN);
			pstmt.setString(1, userName);
			rs = pstmt.executeQuery();
			while(rs.next()){
				pwd = rs.getString(1);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		
		return pwd;
	}

	public String adminLoginDao(String adminName) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;	
		String apwd = null;
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.ADMIN_LOGIN);
			pstmt.setString(1, adminName);
			rs = pstmt.executeQuery();
			while(rs.next()){
				apwd = rs.getString(1);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		
		return apwd;
	}

	public String doctoLoginDao(String doctorName) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;	
		String dpwd = null;
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.DOCTOR_LOGIN);
			pstmt.setString(1, doctorName);
			rs = pstmt.executeQuery();
			while(rs.next()){
				dpwd = rs.getString(1);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		
		return dpwd;
	}

	public Doctor queryDoctorDao(String DOCTOR_NAME){
		// TODO Auto-generated method stub
		List<Doctor> doctor = JDBCDao.queryAll(Doctor.class, UserSql.SQL_QUERY_DOCTOR_BYNAME, DOCTOR_NAME);
		if(doctor.size()>0){
			return doctor.get(0);
		}
		return null;
	}

	public Department queryDepartmentDao(String DEPARTMENT_NAME) {
		// TODO Auto-generated method stub
		List<Department> department = JDBCDao.queryAll(Department.class, UserSql.SQL_QUERY_DEPARTMENT_BYNAME, DEPARTMENT_NAME);
		if(department.size()>0){
			return department.get(0);
		}
		return null;
	}

	public int getCountDao() {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int result=0;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DEPARTMENT_COUNT);
			rs=pstmt.executeQuery();
			while(rs.next()){
				result=rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return result;
	}

	public List<Department> queryDepartmentDao(PageHelper helper) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Department> list = new ArrayList<>();
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DEPARTMENT_FENYE);
			pstmt.setInt(1, helper.getEnd());
			pstmt.setInt(2, helper.getStart());
			rs=pstmt.executeQuery();
			while(rs.next()){
				Department department =new Department();
				department.setDEPARTMENT_ID(rs.getString("DEPARTMENT_ID"));
				department.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				department.setDEPARTMENT_SYNOPSIS(rs.getString("DEPARTMENT_SYNOPSIS"));
				department.setDEPARTMENT_NOTICE_HEAD(rs.getString("DEPARTMENT_NOTICE_HEAD"));
				department.setDEPARTMENT_NOTICE_CONTENT(rs.getString("DEPARTMENT_NOTICE_CONTENT"));
				list.add(department);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return list;
	}

	public List<Doctor> queryDoctorDao(PageHelper helper) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Doctor> list = new ArrayList<>();
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DOCTOR_FENYE);
			pstmt.setInt(1, helper.getEnd());
			pstmt.setInt(2, helper.getStart());
			rs=pstmt.executeQuery();
			while(rs.next()){
				Doctor doctor =new Doctor();
				doctor.setDOCTOR_ID(rs.getString("DOCTOR_ID"));
				doctor.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				doctor.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				doctor.setJOB_TITLE(rs.getString("JOB_TITLE"));
				doctor.setGOOD_JOB(rs.getString("GOOD_JOB"));
				list.add(doctor);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return list;
	}

	public int getCountDoctorDao() {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int result=0;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DOCTOR_COUNT);
			rs=pstmt.executeQuery();
			while(rs.next()){
				result=rs.getInt(1);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return result;
	}

	public boolean queryBySnameDao(String sname) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		boolean bn=false;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DEPARTMENT_BY_NAME);
			pstmt.setString(1, sname);
			rs=pstmt.executeQuery();
			String sName = null;
			
			while(rs.next()){
				Department department =new Department();
				sName = rs.getString(1);
				System.out.println(sName);
				if (sName!=null) {
					bn=true;
				} 
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return bn;
	}

	public int registerGuaHaoDao(GuaHao guaHao) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.GUAHAOREGISTER);
			pstmt.setString(1, guaHao.getDEPARTMENT_NAME());
			pstmt.setString(2, guaHao.getWORK_TIME());
			pstmt.setString(3, guaHao.getDOCTOR_NAME());
			pstmt.setString(4, guaHao.getPATIENT_NAME());
			pstmt.setString(5, guaHao.getSEX());
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public List<Patient> patientQueryDao(String account) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Patient> list =new ArrayList<Patient>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.PATIENT_QUERY_BY_ACCOUNT);
			pstmt.setString(1, account);
			rs = pstmt.executeQuery();
			while(rs.next()){
				Patient patient = new Patient();
				patient.setPATIENT_ID(rs.getString("PATIENT_ID"));
				patient.setPATIENT_NAME(rs.getString("PATIENT_NAME"));
				patient.setAccount(rs.getString("ACCOUNT"));
				patient.setUserPwd(rs.getString("USERPWD"));
				patient.setSex(rs.getString("SEX"));
				patient.setAge(rs.getString("AGE"));
				patient.setTelphone(rs.getString("TELPHONE"));
				patient.setMail(rs.getString("MAIL"));
				list.add(patient);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public List<GuaHao> guaHaoQueryDao(String PATIENT_NAME) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<GuaHao> list =new ArrayList<GuaHao>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.GuaHao_QUERY_BY_PATIENT_NAME);
			pstmt.setString(1, PATIENT_NAME);
			rs = pstmt.executeQuery();
			while(rs.next()){
				GuaHao guaHao = new GuaHao();
				guaHao.setGUAHAO_ID(rs.getString("GUAHAO_ID"));
				guaHao.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				guaHao.setWORK_TIME(rs.getString("WORK_TIME"));
				guaHao.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				guaHao.setMONEY(rs.getString("MONEY"));
				guaHao.setPATIENT_NAME(rs.getString("PATIENT_NAME"));
				guaHao.setSEX(rs.getString("SEX"));
				list.add(guaHao);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public int updatePatientDao(String account,Patient patient) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.UPDATE_PATIENT_BY_ACCOUNT);
			pstmt.setString(1, patient.getUserPwd());
			pstmt.setString(2, patient.getSex());
			pstmt.setString(3, patient.getAge());
			pstmt.setString(4, patient.getTelphone());
			pstmt.setString(5, patient.getMail());
			pstmt.setString(6, account);
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public List<Doctor> doctorQueryDao(String DOCTOR_NAME) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Doctor> list =new ArrayList<Doctor>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.DOCTOR_QUERY_BY_DOCTOR_NAME);
			pstmt.setString(1, DOCTOR_NAME);
			rs = pstmt.executeQuery();
			while(rs.next()){
				Doctor doctor =new Doctor();
				doctor.setDOCTOR_ID(rs.getString("DOCTOR_ID"));
				doctor.setPASSWORD(rs.getString("PASSWORD"));
				doctor.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				doctor.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				doctor.setJOB_TITLE(rs.getString("JOB_TITLE"));
				doctor.setGOOD_JOB(rs.getString("GOOD_JOB"));
				doctor.setJOB_SYNOPSIS(rs.getString("JOB_SYNOPSIS"));
				doctor.setINTRODUCTION(rs.getString("INTRODUCTION"));
				list.add(doctor);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public List<GuaHao> guaHaoQueryByDoctorNameDao(String DOCTOR_NAME) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<GuaHao> list =new ArrayList<GuaHao>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.GuaHao_QUERY_BY_DOCTOR_NAME);
			pstmt.setString(1, DOCTOR_NAME);
			rs = pstmt.executeQuery();
			while(rs.next()){
				GuaHao guaHao = new GuaHao();
				guaHao.setGUAHAO_ID(rs.getString("GUAHAO_ID"));
				guaHao.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				guaHao.setWORK_TIME(rs.getString("WORK_TIME"));
				guaHao.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				guaHao.setMONEY(rs.getString("MONEY"));
				guaHao.setPATIENT_NAME(rs.getString("PATIENT_NAME"));
				guaHao.setSEX(rs.getString("SEX"));
				list.add(guaHao);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public List<Doctor> queryAllDoctorDao() {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Doctor> list =new ArrayList<Doctor>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.DOCTOR_QUERY_ALL);
			rs = pstmt.executeQuery();
			while(rs.next()){
				Doctor doctor =new Doctor();
				doctor.setDOCTOR_ID(rs.getString("DOCTOR_ID"));
				doctor.setPASSWORD(rs.getString("PASSWORD"));
				doctor.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				doctor.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				doctor.setJOB_TITLE(rs.getString("JOB_TITLE"));
				doctor.setGOOD_JOB(rs.getString("GOOD_JOB"));
				doctor.setJOB_SYNOPSIS(rs.getString("JOB_SYNOPSIS"));
				doctor.setINTRODUCTION(rs.getString("INTRODUCTION"));
				list.add(doctor);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public List<GuaHao> queryAllGuaHaoDao() {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<GuaHao> list =new ArrayList<GuaHao>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.GuaHao_QUERY_ALL);
			rs = pstmt.executeQuery();
			while(rs.next()){
				GuaHao guaHao = new GuaHao();
				guaHao.setGUAHAO_ID(rs.getString("GUAHAO_ID"));
				guaHao.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				guaHao.setWORK_TIME(rs.getString("WORK_TIME"));
				guaHao.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				guaHao.setMONEY(rs.getString("MONEY"));
				guaHao.setPATIENT_NAME(rs.getString("PATIENT_NAME"));
				guaHao.setSEX(rs.getString("SEX"));
				list.add(guaHao);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}

	public List<Department> queryAllDepartmentDao() {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Department> list = new ArrayList<>();
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_DEPARTMENT_ALL);
			rs=pstmt.executeQuery();
			while(rs.next()){
				Department department =new Department();
				department.setDEPARTMENT_ID(rs.getString("DEPARTMENT_ID"));
				department.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				department.setDEPARTMENT_SYNOPSIS(rs.getString("DEPARTMENT_SYNOPSIS"));
				department.setDEPARTMENT_NOTICE_HEAD(rs.getString("DEPARTMENT_NOTICE_HEAD"));
				department.setDEPARTMENT_NOTICE_CONTENT(rs.getString("DEPARTMENT_NOTICE_CONTENT"));
				list.add(department);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return list;
	}

	public String queryPatientByNameDao(String PATIENT_NAME) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		String account = null;
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.QUERY_ACCOUNT_BY_PATIENT_NAME);
			pstmt.setString(1, PATIENT_NAME);
			rs = pstmt.executeQuery();
			while(rs.next()){
				account = rs.getString(1);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {				
				e.printStackTrace();
			}
		}
		
		return account;
	}

	public int updateDoctortDao(String DOCTOR_ID, Doctor doctor) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.UPDATE_DOCTOR_BY_DOCTOR_ID);
			pstmt.setString(1, doctor.getDOCTOR_NAME());
			pstmt.setString(2, doctor.getPASSWORD());
			pstmt.setString(3, doctor.getDEPARTMENT_NAME());
			pstmt.setString(4, doctor.getJOB_TITLE());
			pstmt.setString(5, doctor.getGOOD_JOB());
			pstmt.setString(6, doctor.getJOB_SYNOPSIS());
			pstmt.setString(7, doctor.getINTRODUCTION());
			pstmt.setString(8,DOCTOR_ID);
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int deleteDoctortDao(String DOCTOR_ID) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.DELETE_DOCTOR_BY_DOCTOR_ID);
			pstmt.setString(1, DOCTOR_ID);
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int updateDepartmentDao(String DEPARTMENT_ID, Department department) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.UPDATE_DEPARTMENT_BY_DEPARTMENT_ID);
			pstmt.setString(1, department.getDEPARTMENT_SYNOPSIS());
			pstmt.setString(2, department.getDEPARTMENT_NOTICE_CONTENT());
			pstmt.setString(3, department.getDEPARTMENT_NOTICE_HEAD());
			pstmt.setString(4,DEPARTMENT_ID);
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int deleteDepartmentDao(String DEPARTMENT_ID) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.DELETE_DEPARTMENT_BY_DEPARTMENT_ID);
			pstmt.setString(1, DEPARTMENT_ID);
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int addDoctortDao(Doctor doctor) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.ADD_DOCTOR);
			pstmt.setString(1, doctor.getDOCTOR_ID());
			pstmt.setString(2, doctor.getDOCTOR_NAME());
			pstmt.setString(3, doctor.getPASSWORD());
			pstmt.setString(4, doctor.getDEPARTMENT_NAME());
			pstmt.setString(5, doctor.getJOB_TITLE());
			pstmt.setString(6, doctor.getGOOD_JOB());
			pstmt.setString(7, doctor.getJOB_SYNOPSIS());
			pstmt.setString(8, doctor.getINTRODUCTION());
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int addDepartmentDao(Department department) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
		/*	Patient patient=new Patient()*/
			pstmt=conn.prepareStatement(UserSql.ADD_DEPARTMENT);
			pstmt.setString(1, department.getDEPARTMENT_NAME());
			pstmt.setString(2, department.getDEPARTMENT_SYNOPSIS());
			pstmt.setString(3, department.getDEPARTMENT_NOTICE_CONTENT());
			pstmt.setString(4, department.getDEPARTMENT_NOTICE_HEAD());
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public int addNoticeDao(Notice notice) {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt=null;
		int num=0;
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.ADD_NOTICE);
			pstmt.setString(1, notice.getNOTICE_HEAD());
			pstmt.setString(2, notice.getNOTICE_CONTENT());
			num=pstmt.executeUpdate();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return num;
	}

	public List<Notice> noticeQueryDao() {
		// TODO Auto-generated method stub
		Connection conn=null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Notice> list = new ArrayList<>();
		try {
			conn=JDBCUtil.getConn();
			pstmt=conn.prepareStatement(UserSql.QUERY_NOTICE_ALL);
			rs=pstmt.executeQuery();
			while(rs.next()){
				Notice notice =new Notice();
				notice.setNOTICE_HEAD(rs.getString("NOTICE_HEAD"));
				notice.setNOTICE_CONTENT(rs.getString("NOTICE_CONTENT"));
				list.add(notice);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return list;
	}

	public List<Doctor> queryDoctorByDepartmentNameDao(String DEPARTMENT_NAME) {
		// TODO Auto-generated method stub
		Connection conn = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		List<Doctor> list =new ArrayList<Doctor>();
		try {
			conn = JDBCUtil.getConn();
			pstmt = conn.prepareStatement(UserSql.DOCTOR_QUERY_BY_DEPARTMENT_NAME);
			pstmt.setString(1, DEPARTMENT_NAME);
			rs = pstmt.executeQuery();
			while(rs.next()){
				Doctor doctor =new Doctor();
				doctor.setDOCTOR_ID(rs.getString("DOCTOR_ID"));
				doctor.setPASSWORD(rs.getString("PASSWORD"));
				doctor.setDEPARTMENT_NAME(rs.getString("DEPARTMENT_NAME"));
				doctor.setDOCTOR_NAME(rs.getString("DOCTOR_NAME"));
				doctor.setJOB_TITLE(rs.getString("JOB_TITLE"));
				doctor.setGOOD_JOB(rs.getString("GOOD_JOB"));
				doctor.setJOB_SYNOPSIS(rs.getString("JOB_SYNOPSIS"));
				doctor.setINTRODUCTION(rs.getString("INTRODUCTION"));
				list.add(doctor);
			}
		}
		catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				JDBCUtil.CloseAll(conn, pstmt, rs);
			}
			catch (SQLException e) {
				e.printStackTrace();
			}
			
		}
		
		return list;
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值