Java web医院门诊挂号系统(适合初学者)
本系統(tǒng)采用Java +jsp+servlet+mysql+eclipse實(shí)現(xiàn),jdbc編程,具有簡(jiǎn)單的增刪改查等操作,適合初學(xué)者滿足基本的需求。
1、實(shí)體類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連接數(shù)據(jù)
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、效果圖
以上是本系統(tǒng)的重要代碼,希望給大家一個(gè)參考。如若需要源碼或者制定類似的中小型管理系統(tǒng),請(qǐng)加QQ1728608455.,歡迎咨詢
?
?
?
總結(jié)
以上是生活随笔為你收集整理的Java web医院门诊挂号系统(适合初学者)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中软国际第十天
- 下一篇: bundle打包自动转换tiff格式的处