Java实现医院管理系统

本文实例为大家分享了Java实现医院管理系统的具体代码,供大家参考,具体内容如下

1.开发工具

NetBeans8.2
Mysql5.7
mysql-connector-java-5.1.6.jar

2.演示

登录界面

增删查改界面

3.源码

CREATE TABLE user (
username varchar(255) NOT NULL,
password varchar(255) DEFAULT NULL,
PRIMARY KEY (username)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE doctor_info (
no varchar(45) NOT NULL,
name varchar(45) DEFAULT NULL,
departments varchar(45) DEFAULT NULL,
level varchar(45) DEFAULT NULL,
ghf varchar(45) DEFAULT NULL,
PRIMARY KEY (no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
package 经典增删查改;
import com.mysql.jdbc.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

public class Login extends javax.swing.JFrame {

 private int flag;
 public Login() {
  initComponents();
 }

 /**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.
 */
 @SuppressWarnings("unchecked")
 // <editor-fold defaultstate="collapsed" desc="Generated Code">
 private void initComponents() {

  jLabel1 = new javax.swing.JLabel();
  jLabel2 = new javax.swing.JLabel();
  jTextField2 = new javax.swing.JTextField();
  jPasswordField1 = new javax.swing.JPasswordField();
  jButton2 = new javax.swing.JButton();
  jButton3 = new javax.swing.JButton();

  setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

  jLabel1.setText("账号");

  jLabel2.setText("密码");

  jTextField2.setText(" ");

  jButton2.setText("登录");
  jButton2.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton2ActionPerformed(evt);
   }
  });

  jButton3.setText("退出");
  jButton3.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    jButton3ActionPerformed(evt);
   }
  });

  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  getContentPane().setLayout(layout);
  layout.setHorizontalGroup(
   layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   .addGroup(layout.createSequentialGroup()
    .addGap(103, 103, 103)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
     .addComponent(jLabel2)
     .addComponent(jLabel1))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
     .addGroup(layout.createSequentialGroup()
      .addComponent(jButton2)
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 35, Short.MAX_VALUE)
      .addComponent(jButton3))
     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
      .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
      .addComponent(jPasswordField1)))
    .addContainerGap(114, Short.MAX_VALUE))
  );
  layout.setVerticalGroup(
   layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   .addGroup(layout.createSequentialGroup()
    .addGap(69, 69, 69)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
     .addComponent(jLabel1)
     .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
     .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
     .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addGap(18, 18, 18)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
     .addComponent(jButton2)
     .addComponent(jButton3))
    .addContainerGap(49, Short.MAX_VALUE))
  );

  pack();
 }// </editor-fold>      

 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
  System.exit(0);
 }          

 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
  try {
   Connection con = DBConnection.getConnection();
   Statement stmt = con.createStatement();
   String sql="select *from user";
   ResultSet rs = stmt.executeQuery(sql);
   String usename=jTextField2.getText().trim();
   char[] p=jPasswordField1.getPassword();
   String pwd=new String(p);
   String name = null;
   String pass = null;
   while(rs.next()){
    name=rs.getString(1);
    pass=rs.getString(2);
    if(usename.equals(name)&&pwd.equals(pass)){
     System.out.println("登录成功!!");

     new doctorInfoGui().setVisible(true);
     this.dispose();

    }
    }

  } catch (ClassNotFoundException ex) {
   Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
  } catch (SQLException ex) {
   Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
  }
 }          

 /**
 * @param args the command line arguments
 */
 public static void main(String args[]) {
  /* Set the Nimbus look and feel */
  //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  */
  try {
   for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
     javax.swing.UIManager.setLookAndFeel(info.getClassName());
     break;
    }
   }
  } catch (ClassNotFoundException ex) {
   java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (InstantiationException ex) {
   java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (IllegalAccessException ex) {
   java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (javax.swing.UnsupportedLookAndFeelException ex) {
   java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  }
  //</editor-fold>

  /* Create and display the form */
  java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
    new Login().setVisible(true);
   }
  });
 }

 // Variables declaration - do not modify
 private javax.swing.JButton jButton2;
 private javax.swing.JButton jButton3;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JPasswordField jPasswordField1;
 private javax.swing.JTextField jTextField2;
 // End of variables declaration
}
package 经典增删查改;
import java.awt.event.KeyEvent;

import javax.swing.JOptionPane;
public class doctorInfoGui extends javax.swing.JFrame {
 public doctorInfoGui() {
  initComponents();
  String sql="select*from doctor_info";
  //doctorInfo看作为一个TableModel
  doctorInfo d=new doctorInfo (sql);
  //教你如何添加数据的方法
  jTable1.setModel(d);
  System.out.println(" 已经给表添加好了数据!");
 }

 private void initComponents() {

  jtfseacher = new javax.swing.JTextField();
  jbtseacher = new javax.swing.JButton();
 ///////////////////////////////////////////////////////////////////
   //Alt+Enter
  jbtseacher.setMnemonic(KeyEvent.VK_ENTER);

  jScrollPane1 = new javax.swing.JScrollPane();
  jScrollPane2 = new javax.swing.JScrollPane();
  jTable1 = new javax.swing.JTable();
  jLabel1 = new javax.swing.JLabel();
  jLabel2 = new javax.swing.JLabel();
  jLabel3 = new javax.swing.JLabel();
  jLabel4 = new javax.swing.JLabel();
  jLabel5 = new javax.swing.JLabel();
  jtfno = new javax.swing.JTextField();
  jtfname = new javax.swing.JTextField();
  jTextFieldks = new javax.swing.JTextField();
  jtflevel = new javax.swing.JTextField();
  jtfghf = new javax.swing.JTextField();
  jbtAdd = new javax.swing.JButton();
  Updatajbt = new javax.swing.JButton();
  jbtUpdata = new javax.swing.JButton();
  jLabel6 = new javax.swing.JLabel();
  deletejbt = new javax.swing.JButton();
  jbtClear = new javax.swing.JButton();
  jLabel7 = new javax.swing.JLabel();

  setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

  jbtseacher.setText("查询");
  jtfseacher.setToolTipText("按姓名查询");
  jbtseacher.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtseacherActionPerformed(evt);
   }
  });

  jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
   public void mouseClicked(java.awt.event.MouseEvent evt) {
    jTable1MouseClicked(evt);
   }
  });
  jScrollPane2.setViewportView(jTable1);

  jScrollPane1.setViewportView(jScrollPane2);

  jLabel1.setText("编号");

  jLabel2.setText("姓名");

  jLabel3.setText("科室");

  jLabel4.setText("级别");

  jLabel5.setText("挂号费");

  jtfno.setText(" ");

  jtfname.setText(" ");

  jtflevel.setText(" ");

  jtfghf.setText(" ");

  jbtAdd.setText("添加");
  jbtAdd.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtAddActionPerformed(evt);
   }
  });

  Updatajbt.setText("修改");
  Updatajbt.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    UpdatajbtActionPerformed(evt);
   }
  });

  jLabel6.setText("姓名");

  deletejbt.setText("删除");
  deletejbt.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    deletejbtActionPerformed(evt);
   }
  });

  jbtClear.setText("清空");
  jbtClear.addActionListener(new java.awt.event.ActionListener() {
   public void actionPerformed(java.awt.event.ActionEvent evt) {
    jbtClearActionPerformed(evt);
   }
  });

  jLabel7.setText("科室");

  jTextFieldks.setText(" ");

  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  getContentPane().setLayout(layout);
  layout.setHorizontalGroup(
   layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   .addGroup(layout.createSequentialGroup()
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE))
     .addGroup(layout.createSequentialGroup()
      .addGap(81, 81, 81)
      .addComponent(jtfseacher, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(39, 39, 39)
      .addComponent(jbtseacher)
      .addGap(32, 32, 32)
      .addComponent(deletejbt))
     .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
       .addGroup(layout.createSequentialGroup()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jtfno, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
       .addGroup(layout.createSequentialGroup()
        .addComponent(jLabel6)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jtfname, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
       .addGroup(layout.createSequentialGroup()
        .addGap(32, 32, 32)
        .addComponent(jLabel4)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jtflevel, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE))
       .addGroup(layout.createSequentialGroup()
        .addGap(18, 18, 18)
        .addComponent(jLabel5)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addComponent(jtfghf, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)))
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
       .addGroup(layout.createSequentialGroup()
        .addGap(55, 55, 55)
        .addComponent(jbtUpdata))
       .addGroup(layout.createSequentialGroup()
        .addGap(30, 30, 30)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
          .addComponent(jLabel7)
          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
          .addComponent(jTextFieldks, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
         .addGroup(layout.createSequentialGroup()
          .addComponent(jbtAdd)
          .addGap(10, 10, 10)
          .addComponent(jbtClear)
          .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
          .addComponent(Updatajbt)))))))
    .addContainerGap())
   .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addComponent(jLabel3)
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addComponent(jLabel2))));

  layout.setVerticalGroup(
   layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
   .addGroup(layout.createSequentialGroup()
    .addGap(17, 17, 17)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
     .addComponent(jtfseacher, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
     .addComponent(jbtseacher)
     .addComponent(deletejbt))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 172, javax.swing.GroupLayout.PREFERRED_SIZE)
     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)

      .addComponent(jbtUpdata)))
    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
     .addGroup(layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
       .addComponent(jLabel1)
       .addComponent(jLabel4)
       .addComponent(jtfno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
       .addComponent(jtflevel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
       .addComponent(jLabel7)
       .addComponent(jTextFieldks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(8, 8, 8)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
       .addComponent(jLabel5)
       .addComponent(jtfname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
       .addComponent(jtfghf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
       .addComponent(jLabel6))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
      .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addContainerGap(39, Short.MAX_VALUE))
     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
        .addComponent(jbtClear)
        .addComponent(Updatajbt))
       .addComponent(jbtAdd, javax.swing.GroupLayout.Alignment.LEADING))
      .addGap(43, 43, 43))))
  );

  pack();
 }// </editor-fold>      

 private void jbtseacherActionPerformed(java.awt.event.ActionEvent evt) {
   String text=jtfseacher.getText().trim();
   //重新执行查询sql语句,在读取数据,然后再添加到Table表格中,实现刷新表格的作用
   String sql="select*from doctor_info where name='"+text+"'";
   doctorInfo d=new doctorInfo (sql);
   jTable1.setModel(d);
   jtfseacher.setText("");

 }           

 private void jbtAddActionPerformed(java.awt.event.ActionEvent evt) {
   String no=jtfno.getText().trim();
   String name=jtfname.getText().trim();
   String ks= jTextFieldks.getText().trim();
   String level=jtflevel.getText().trim();
   String ghf=jtfghf.getText().trim();

   //执行添加sql语句,再读取数据
   String sql = "INSERT INTO doctor_info(no,name ,departments,level,ghf) VALUES('" + no + "','" + name+ "', '" + ks+ "', '" + level + "','"+ghf+"')";
   doctorInfo df=new doctorInfo ();
   df.Add(sql);
   //
   //重新读取数据
   String sql1="select*from doctor_info";
   doctorInfo d=new doctorInfo (sql1);
   jTable1.setModel(d);

   jtfno.setText("");
   jtfname.setText("");
   jtflevel.setText("");
   jtfghf.setText("");
   jTextFieldks.setText("");
 }          

 private void UpdatajbtActionPerformed(java.awt.event.ActionEvent evt) {
  //获取当前位置
  int index = jTable1.getSelectedRow();
  //获取莫一行的第0列的值,注意获取的行数需要减少一个
  String id = jTable1.getValueAt(index-1, 0).toString() ;

  String no=jtfno.getText().trim();
  String name=jtfname.getText().trim();
  String ks= jTextFieldks.getText().trim();
  String level=jtflevel.getText().trim();
  String ghf=jtfghf.getText().trim();

  jtfno.setText("");
  jtfname.setText("");
  jtflevel.setText("");
  jtfghf.setText("");
  jTextFieldks.setText("");

  String sql = "UPDATE doctor_info SET name ='" + name + "',departments='" + ks + "',level='" + level+ "',ghf='" + ghf + "' WHERE no='" + no+ "'";
  System.out.println(id);
  System.out.println(no);
  doctorInfo df=new doctorInfo ();
  df.Update(sql);

  //重新读取数据
  String sql1="select*from doctor_info";
  doctorInfo d=new doctorInfo (sql1);
  jTable1.setModel(d);

 }          

 private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {
  //获取某一行的具体值,并把它显示在文本框中
  String no = jTable1.getValueAt(jTable1.getSelectedRow(), 0).toString();
  String name = jTable1.getValueAt(jTable1.getSelectedRow(), 1).toString();
  String ks = jTable1.getValueAt(jTable1.getSelectedRow(), 2).toString();
  String level = jTable1.getValueAt(jTable1.getSelectedRow(), 3).toString();
  String ghf= jTable1.getValueAt(jTable1.getSelectedRow(), 4).toString();
  //把点击的内容显示在文本框中
  jtfno.setText(no);
  jtfname.setText(name);
  jTextFieldks.setText(ks);
  jtflevel.setText(level);
  jtfghf.setText(ghf);

 }         

 private void deletejbtActionPerformed(java.awt.event.ActionEvent evt) {
   //设置选择对话框的选项
  String[] options = {"是", "否"};
  int answ = JOptionPane.showOptionDialog(null, "是否确认删除??", "提示", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

  if (answ == 0) {
   int index = jTable1.getSelectedRow();
   String id = jTable1.getValueAt(index, 0).toString();
   String sql="delete from doctor_info where no='"+id+"'";

   // 删除一条记录
   doctorInfo df=new doctorInfo ();
   df.delete(sql);
   System.out.println("删除成功!!!");

   //重新读取数据
   String sql1="select*from doctor_info";
   doctorInfo d=new doctorInfo (sql1);
    jTable1.setModel(d);

    jtfno.setText("");
    jtfname.setText("");
    jtflevel.setText("");
    jtfghf.setText("");
    jTextFieldks.setText("");

   } else
   {
    JOptionPane.showMessageDialog(null, "无法删除!!!");
   }
 }          

 private void jbtClearActionPerformed(java.awt.event.ActionEvent evt) {
   jtfno.setText("");
   jtfname.setText("");
   jtflevel.setText("");
   jtfghf.setText("");
   jTextFieldks.setText("");
 }          

 public static void main(String args[]) {
  /* Set the Nimbus look and feel */
  //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
   * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
   */
  try {
   for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
    if ("Nimbus".equals(info.getName())) {
     javax.swing.UIManager.setLookAndFeel(info.getClassName());
     break;
    }
   }
  } catch (ClassNotFoundException ex) {
   java.util.logging.Logger.getLogger(doctorInfoGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (InstantiationException ex) {
   java.util.logging.Logger.getLogger(doctorInfoGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (IllegalAccessException ex) {
   java.util.logging.Logger.getLogger(doctorInfoGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  } catch (javax.swing.UnsupportedLookAndFeelException ex) {
   java.util.logging.Logger.getLogger(doctorInfoGui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  }
  //</editor-fold>

  /* Create and display the form */
  java.awt.EventQueue.invokeLater(new Runnable() {
   public void run() {
    new doctorInfoGui().setVisible(true);
   }
  });
 }

 // Variables declaration - do not modify
 private javax.swing.JButton Updatajbt;
 private javax.swing.JButton deletejbt;
 private javax.swing.JLabel jLabel1;
 private javax.swing.JLabel jLabel2;
 private javax.swing.JLabel jLabel3;
 private javax.swing.JLabel jLabel4;
 private javax.swing.JLabel jLabel5;
 private javax.swing.JLabel jLabel6;
 private javax.swing.JLabel jLabel7;
 private javax.swing.JScrollPane jScrollPane1;
 private javax.swing.JScrollPane jScrollPane2;
 private javax.swing.JTable jTable1;

 private javax.swing.JButton jbtAdd;
 private javax.swing.JButton jbtClear;
 private javax.swing.JButton jbtUpdata;
 private javax.swing.JButton jbtseacher;
 private javax.swing.JTextField jtfghf;
 private javax.swing.JTextField jTextFieldks;
 private javax.swing.JTextField jtflevel;
 private javax.swing.JTextField jtfname;
 private javax.swing.JTextField jtfno;
 private javax.swing.JTextField jtfseacher;
 // End of variables declaration
}
package 经典增删查改;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;

public class doctorInfo extends AbstractTableModel {
  Connection con=null;
  PreparedStatement ps=null;
  ResultSet rs=null;
  Vector<Serializable> rowData,columnName;
  public doctorInfo(String sql){
   init( sql) ;
  }

  public doctorInfo(){

  }
  public void init(String sql){

    //columnName保存表头信息
    columnName=new Vector<Serializable>();
    columnName.add("编号");
    columnName.add("姓名");
    columnName.add("科室");
    columnName.add("级别");
    columnName.add("挂号费");

   //rowData向量保存每一行的信息
   rowData=new Vector<Serializable>();
   try {
   con = DBConnection.getConnection();
    ps=(PreparedStatement) con.prepareStatement( sql);
    rs=ps.executeQuery();
   while(rs.next()){
     Vector bang=new Vector();
     bang.add(rs.getString(1) );
     bang.add(rs.getString(2) );
     bang.add(rs.getString(3) );
     bang.add(rs.getString(4) );
     bang.add(rs.getString(5) );

     //将读取的每一行数据添加到bang中,然后再把bang添加到rowData向量中
     rowData.add(bang);
   }
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }finally {
   if(con!=null&&ps!=null&rs!=null){
    try {
     con.close();
     ps.close();
     rs.close();
    } catch (SQLException e) {

     e.printStackTrace();
    }

   }
  }
 }
 public void chushihua(String sql){
   Connection con=null;
   PreparedStatement ps=null;
  int rs;

  try {
   con = DBConnection.getConnection();
    ps=(PreparedStatement) con.prepareStatement( sql);
    rs=ps.executeUpdate();

  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 public void delete(String sql){
  chushihua( sql);

 }
 public void Add(String sql){
  chushihua( sql);

 }

 public void Update(String sql){
  chushihua( sql);

 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 @Override
 public int getRowCount() {
  return this.rowData.size();
 }

 @Override
 public int getColumnCount() {
  return this.columnName.size();
 }

 @Override
 public Object getValueAt(int row, int column) {
  return ((Vector ) this.rowData.get(row)).get(column);
 }
 public String getColumnName(int column) {

  return (String) this.columnName.get(column);
 }

 }
package 经典增删查改;
import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
class DBConnection{
  public static Connection getConnection() throws ClassNotFoundException {
  // JDBC 驱动名及数据库 URL
  String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  String URL = "jdbc:mysql://localhost:3306/hospital";
  String USER = "root";
  String PASSWORD = "root";
  Connection conn = null; 

   //与数据库建立连接
    Class.forName(JDBC_DRIVER);
   try {
    conn= (Connection) DriverManager.getConnection(URL,USER,PASSWORD);
   System.out.println("已经连接数据库");

   } catch (SQLException ex) {
    Logger.getLogger(DBConnection.class.getName()).log(Level.SEVERE, null, ex);
   }

  return conn;
 } 

}

网上难找一个带界面的管理系统源码,我把这简单管理系统分享出去,希望能够帮助到那些需要帮助的人。

更多学习资料请关注专题《管理系统开发》。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • java实现科研信息管理系统

    一.前言 本学期学习了JAVA语言,在学期的结束,写一个有操作界面,与数据库关联的管理系统,用来巩固自己本学习所学的知识. 用到的知识:JAVA基础,JAVA界面设计(GUI),Oracle数据库(需要掌握数据库的基本操作语句),链接数据库. 使用的开发工具:MyEclipse Professional 2014 二.设计 我们管理的属性有:项目编号,项目名称,参与人员,负责人,项目开始时间,结束时间.科研项目系统主要有四个功能,对科研项目的增加.删除.修改.查询.以及为增加系统安全性所设计的登

  • 一个简陋的java图书管理系统

    本文代码为原创一个简陋的管理系统,只做功能的测试.并没有去完善所有应有的功能,只做了输入输出查找,仅供参考! 菜单部分: import java.util.Scanner; public class Menu { int Min = 1; int Max = 3; public void getMenu(){ System.out.println("1.显示/2.输入/3.查找"); } public void getFindMenu(){ System.out.println(&qu

  • 简单实现Java版学生管理系统

    本文实例为大家分享了Java实现学生管理系统的具体代码,供大家参考,具体内容如下 package BookDemo_1; import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Test { public static void main(String[] args) { StudentSys stuSys=new StudentSys("学生管理系统"); stuSys.initWi

  • 图书管理系统java代码实现

    本文实例为大家分享了java实现图书管理系统的具体代码,供大家参考,具体内容如下 /* (程序头部注释开始) * 程序的版权和版本声明部分 * Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved. * 文件名称:    <图书管理系统--java>                          * 作    者:       刘江波                       * 完成日期:    2012     年  3    

  • java实现客房管理系统

    本文实例为大家分享了java实现客房管理系统的具体代码,供大家参考,具体内容如下 AddClient.java import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.A

  • Java实现租车管理系统

    需求: 完成一个和用户互动的租车管理系统,当中包括基础的增删改查,以及输出实时地热度排行榜! 功能设计: 在工程的包com.Test02中,搭建4个类,分别是程序启动(carSysStart).控制台(carConsole).数据存储内存库(carData_base).系统的功能类(carFunction) 具体代码如下: 1.程序启动 package com.Test02; public class carSysStart { public static void main(String[]

  • Java swing实现酒店管理系统

    今天给大家提供一个由今天给大家提供一个由Java swing实现的酒店管理系统,数据库采用sqlserver,我会贴上部分代码,完整的代码请看文章最下方下载,下面看代码: 1.主框架代码: package 主框架窗口; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.event.ActionEven

  • 图书管理系统java版

    本文的目的就是通过图书管理系统掌握数据库编程技术,能正确连接数据库,能对数据库中信息进行查询.插入.删除.修改. 内容:在数据库中创建一张书目信息表,包括书名.作者.出版社.出版日期.书号.价格字段.设计一个GUI界面进行书目管理.在该界面上有四个选项卡,分别是查询.插入.删除.修改.点击查询选项卡,出现的界面上有书名.作者.出版社.书号四个文本框,一个按钮和一个只读文本区.文本框内容可以为空,输入相应的查询信息后(例如根据书名查询可以仅输入书名),点击界面上的"查询"按钮,可以在界面

  • Java+Mysql学生管理系统源码

    最近正在学java和数据库,想起以前写的学生管理系统,都是从网上下载,敷衍了事.闲来无事,也就自己写了一个,不过功能实现的不是很多. 开发语言:java: 开发环境:Mysql, java: 开发工具:eclipse 开发此案例,首先得在电脑上有java开发环境和Mysql, java开发环境与Mysql的搭建,就不再叙述了,如果需要,请联系我最下面的联系方式:dingyelf@aliyun.com 此次系统比较简易:数据库中只有一个表:stu;功能:能够对学生增加.删除.修改. 开发步骤:  

  • Java实现酒店客房管理系统

    本文实例为大家分享了Java实现酒店客房管理系统的具体代码,供大家参考,具体内容如下 LoginFrame.java package loginManage; import java.awt.Color; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing

随机推荐