Java web醫院門診掛號系統(適合初學者)

本系統採用Java +jsp+servlet+mysql+eclipse實現,jdbc編程,具有簡單的增刪改查等操作,適合初學者滿足基本的需求。

1、實體類GuaHao和User類。

package entity;

public class User {
    private Integer id;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    private String username;
    private String password;

}

package entity;

import java.sql.Date;

public class Guahao {
    
    private Integer id;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public Integer getNo() {
        return no;
    }
    public void setNo(Integer no) {
        this.no = no;
    }
    public String getCondation() {
        return condation;
    }
    public void setCondation(String condation) {
        this.condation = condation;
    }
    public String gethName() {
        return hName;
    }
    public void sethName(String hName) {
        this.hName = hName;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    private Integer no;
    private String condation;
    private String hName;
    private Date createTime;

}


2.Jdbc連接數據


public class DBConnection {
    final static String DRIVER="com.mysql.jdbc.Driver";
    final static String URL="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8";
    final static String USER="root";
    final static String PASSWORD="123456";
    public static Connection getConnection(){
        try{
            Class.forName(DRIVER);
            Connection connection=DriverManager.getConnection(URL,USER,PASSWORD);
            return connection;
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }
    
    public static void closeConnection(Connection c){
        try{
            c.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    } 
    
    public static void main(String[] args){
        System.out.println("綠色"+DBConnection.getConnection());
    }


}
 


3、Dao層

package mapper;

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 entity.Guahao;
import utils.DBConnection;
public class GuhaoMapper {
    
    
    public List<Guahao> get_ListInfo(){
        List<Guahao> list = new ArrayList<Guahao>();
        Connection conn=DBConnection.getConnection();
        String sql = "select * from guahao";
        PreparedStatement stm = null;
        ResultSet rs = null;
        try {
            stm = conn.prepareStatement(sql);
            rs = stm.executeQuery();
            while(rs.next()){
                Guahao gh = new Guahao();
                gh.setId(rs.getInt("id"));
                gh.setNo(rs.getInt("no"));
                gh.setCondation(rs.getString("condation"));
                gh.sethName(rs.getString("hName"));
                gh.setCreateTime(rs.getDate("createTime"));
                list.add(gh);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally{
            DBConnection.closeConnection(conn);
        }
        return list;
    }
    
    public boolean insert(Guahao guahao){
        Connection conn=DBConnection.getConnection();
        String sql = "insert  into guahao(no,condation,hName,createTime) values(?,?,?,?)";
        
        try{
            PreparedStatement pst=conn.prepareStatement(sql);
            pst.setInt(1, guahao.getNo());
            pst.setString(2, guahao.getCondation());
            pst.setString(3, guahao.gethName());
            pst.setDate(4,guahao.getCreateTime());
            pst.execute();
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }finally{
            DBConnection.closeConnection(conn);
        }
        
    }
    
    
    
    public boolean update(Guahao guahao,int id) {
         Connection conn=null;
         PreparedStatement stm=null;
         ResultSet rs=null;
         try{
             conn=DBConnection.getConnection();
            String sql="update guahao set no=?,condation=?,hName=?,createTime=? where id=?";
            stm=conn.prepareStatement(sql);
            stm.setInt(1,guahao.getNo());
            stm.setString(2, guahao.getCondation());
            stm.setString(3, guahao.gethName());
            stm.setDate(4, guahao.getCreateTime());
            stm.setInt(5,id);
            stm.execute();
            return true;
         
         }catch(Exception e){
             e.printStackTrace();
             return false;
         }finally{
             DBConnection.closeConnection(conn);
         }
    }
    
    
    
    public List<Guahao> findByNo(int no){    
        Connection conn=null; 
        List<Guahao> list =new ArrayList<Guahao>();
        ResultSet rs=null;
        PreparedStatement stm=null;
        try{
            conn=DBConnection.getConnection();
            String sql="select * from guahao where  no=?";
            stm=conn.prepareStatement(sql);
            stm.setInt(1, no);
            rs=stm.executeQuery();
            while(rs.next()) {
                Guahao gh =new Guahao();
                gh.setId(rs.getInt("id"));
                gh.setNo(rs.getInt("no"));
                gh.setCondation(rs.getString("condation"));
                gh.sethName(rs.getString("hName"));
                gh.setCreateTime(rs.getDate("createTime"));
                list.add(gh);
                
            }
            return list;
            }catch(Exception e){
            e.printStackTrace();
                return null;
        }finally{
            DBConnection.closeConnection(conn);
        }
        
    }
    
    public Guahao queryById(int id){
        
        Connection conn=null;
        PreparedStatement stm=null;
        ResultSet rs=null;
        try{
            conn=DBConnection.getConnection();
            String sql="select * from guahao where id=?";
            stm=conn.prepareStatement(sql);
            stm.setInt(1,id);            
            rs=stm.executeQuery();
            if(rs.next()){
                Guahao gh =new Guahao();
                gh.setId(rs.getInt("id"));
                gh.setNo(rs.getInt("no"));
                gh.setCondation(rs.getString("condation"));
                gh.sethName(rs.getString("hName"));
                gh.setCreateTime(rs.getDate("createTime"));
                return gh;
            }else{
                return null;
            }
        }catch(Exception e){
            e.printStackTrace();
            return null;
        }finally{
            DBConnection.closeConnection(conn);
        }
        
    }
    public boolean delete( int id) {
        Connection conn=null;
        
        try{
            conn=DBConnection.getConnection();
            String sql="delete from guahao where id=?";
            PreparedStatement pst=conn.prepareStatement(sql);
            pst.setInt(1,id);
            pst.execute();
            return true;
        }catch(Exception e){
            e.printStackTrace();
            return false;
        }finally{
            DBConnection.closeConnection(conn);
        }
        
    }

}


4、效果圖


以上是本系統的重要代碼,希望給大家一個參考。如若需要源碼或者制定類似的中小型管理系統,請加QQ1728608455.,歡迎諮詢
 


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章