Hospital Database Management System Template

Basically, this database system is maintained in two parts, front-end is implemented using simple JAVA GUI, while the back-end is supported by MySQL.

In this initial version, there is no framework to follow. However, the basic structure is maintained using different classes in JAVA. The main frame is called "Login", where all Buttons, Panels and Text and other features are located. The main class is called Login, action listeners are embedded, for responding automatically for user's operation. Sub-sections include action-performed, where account fetching and matching are performed, i.e. if you were a medical staff then in the corresponding database there must store the corresponding account information. Showing below is the java code for login class.

package Hospital;

/**
 * Created by maoyuanqi on 2017/12/4.
 */



import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Login extends JFrame implements ActionListener {

    //component define
    JButton jb1,jb2,jb3=null;
    JRadioButton jrb1,jrb2,jrb3,jrb4,jrb5=null;
    JPanel jp1,jp2,jp3,jp4=null;
    JTextField jtf=null;
    JLabel jlb1,jlb2,jlb3=null;
    JPasswordField jpf=null;
    ButtonGroup bg=null;

    //menu
    JMenuBar jmb=null;
    JMenu jm=null;
    JMenuItem jmi1,jmi2=null;


    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Login ms=new Login();


    }
    //
    public Login()
    {
        //component
        jb1=new JButton("Login");
        jb2=new JButton("Reset");
        jb3=new JButton("Exit");
        //listener
        jb1.addActionListener(this);
        jb2.addActionListener(this);
        jb3.addActionListener(this);

        jmb=new JMenuBar();
        jm=new JMenu("Please Login First");
        jmi1=new JMenuItem("Start");
        jmi2=new JMenuItem("Quit");
        jm.add(jmi1);
        jm.add(jmi2);
        jmb.add(jm);


        jrb1=new JRadioButton("HR",true);
        jrb2=new JRadioButton("FINANCE");
        jrb3=new JRadioButton("RECEPTIONIST");
        jrb4=new JRadioButton("CLINIC");
        jrb5=new JRadioButton("MEDICINE");
        bg=new ButtonGroup();
        bg.add(jrb1);
        bg.add(jrb2);
        bg.add(jrb3);
        bg.add(jrb4);
        bg.add(jrb5);


        jp1=new JPanel();
        jp2=new JPanel();
        jp3=new JPanel();
        jp4=new JPanel();

        jlb1=new JLabel("        id:");
        jlb2=new JLabel("  password:  ");
        jlb3=new JLabel("Department:  ");

        jtf=new JTextField(3);
        jpf=new JPasswordField(6);
        //join in JP
        jp1.add(jlb1);
        jp1.add(jtf);
        jp2.add(jlb2);
        jp2.add(jpf);

        jp3.add(jlb3);
        jp3.add(jrb1);
        jp3.add(jrb2);
        jp3.add(jrb3);
        jp3.add(jrb4);
        jp3.add(jrb5);

        jp4.add(jb1);
        jp4.add(jb2);
        jp4.add(jb3);

        //join in JF
        this.setJMenuBar(jmb);
        this.add(jp1);
        this.add(jp2);
        this.add(jp3);
        this.add(jp4);

        //layout setting
        this.setLayout(new GridLayout(4,1));
        //title setting
        this.setTitle("Hospital Database Management System");
        //window size
        this.setSize(600,500);
        //initial positioning
        this.setLocation(200, 150);
        //Real-time closing
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        //set visible
        this.setVisible(true);
        this.setResizable(true);

    }

    public void actionPerformed(ActionEvent e) {

        if(e.getActionCommand()=="Exit")
        {
            System.exit(0);
        }else if(e.getActionCommand()=="Login")
        {
            //Connecting to sql
            GetSQL.ConnectSQL();
            //if HR is selected.
            if(jrb1.isSelected())
            {
                Integer a=Integer.parseInt(jtf.getText());
                GetSQL.sqlquery("HR", a);
                this.HRlogin();
            }else if(jrb2.isSelected()) //finance is selected.
            {
                Integer a=Integer.parseInt(jtf.getText());
                GetSQL.sqlquery("FINANCE", a);
                this.FINANCE_login();
            }else if (jrb3.isSelected()){
                Integer a=Integer.parseInt(jtf.getText());
                GetSQL.sqlquery("RECEPTIONIST", a);
                this.RECEPTIONIST_login();
            }
            else if (jrb4.isSelected()){
                Integer a=Integer.parseInt(jtf.getText());
                GetSQL.sqlquery("CLINIC", a);
                this.CLINIC_login();
            }
            else if (jrb5.isSelected()){
                Integer a=Integer.parseInt(jtf.getText());
                GetSQL.sqlquery("MEDICINE", a);
                this.MEDICINE_login();
            }

        }else if(e.getActionCommand()=="Reset")
        {
            this.clear();
        }

    }

    //
    public  void clear()
    {
        jtf.setText("");
        jpf.setText("");
    }
    //
    public void HRlogin()
    {
        System.out.println(jtf.getText()+"  "+jpf.getText());
        if (GetSQL.userword ==Integer.parseInt(jtf.getText()) && GetSQL.pwd.equals(jpf.getText()))
        {
//                  System.out.println("Login Succeed!");
            JOptionPane.showMessageDialog(null,"Login Succeed!!","Message",JOptionPane.WARNING_MESSAGE);
            this.clear();

            dispose();
           HR_UI ui=new HR_UI();
        }else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username and password!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jtf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter password!","Message",JOptionPane.WARNING_MESSAGE);
        }else
        {
            JOptionPane.showMessageDialog(null,"username or password fails!\nplease enter again","Message",JOptionPane.ERROR_MESSAGE);
            //
            this.clear();
        }
    }
    //
    public void FINANCE_login()
    {
        System.out.println(jtf.getText()+"  "+jpf.getText());
        if (GetSQL.userword ==Integer.parseInt(jtf.getText()) && GetSQL.pwd.equals(jpf.getText()))
        {
//                  System.out.println("Login Succeed!");
            JOptionPane.showMessageDialog(null,"Login Succeed!!","Message",JOptionPane.WARNING_MESSAGE);
            this.clear();
            //
            dispose();
            //
            FINANCE_UI ui=new FINANCE_UI();
        }else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username and password!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jtf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter password!","Message",JOptionPane.WARNING_MESSAGE);
        }else
        {
            JOptionPane.showMessageDialog(null,"username or password fails!\nplease enter again","Message",JOptionPane.ERROR_MESSAGE);
            //
            this.clear();
        }
    }
    //
    public void RECEPTIONIST_login()
    {
        System.out.println(jtf.getText()+"  "+jpf.getText());
        if (GetSQL.userword ==Integer.parseInt(jtf.getText()) && GetSQL.pwd.equals(jpf.getText()))
        {
//                  System.out.println("Login Succeed!");
            JOptionPane.showMessageDialog(null,"Login Succeed!!","Message",JOptionPane.WARNING_MESSAGE);
            this.clear();
            //
            dispose();
            //
            RECEPTIONIST_UI ui=new RECEPTIONIST_UI();
        }else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username and password!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jtf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter password!","Message",JOptionPane.WARNING_MESSAGE);
        }else
        {
            JOptionPane.showMessageDialog(null,"username or password fails!\nplease enter again","Message",JOptionPane.ERROR_MESSAGE);
            //
            this.clear();
        }
    }
    public void CLINIC_login()
    {
        System.out.println(jtf.getText()+"  "+jpf.getText());
        if (GetSQL.userword ==Integer.parseInt(jtf.getText()) && GetSQL.pwd.equals(jpf.getText()))
        {
//                  System.out.println("Login Succeed!");
            JOptionPane.showMessageDialog(null,"Login Succeed!!","Message",JOptionPane.WARNING_MESSAGE);
            this.clear();
            //
            dispose();
            //
            CLINIC_UI ui=new CLINIC_UI();
        }else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username and password!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jtf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter password!","Message",JOptionPane.WARNING_MESSAGE);
        }else
        {
            JOptionPane.showMessageDialog(null,"username or password fails!\nplease enter again","Message",JOptionPane.ERROR_MESSAGE);
            //
            this.clear();
        }
    }
    public void MEDICINE_login()
    {
        System.out.println(jtf.getText()+"  "+jpf.getText());
        if (GetSQL.userword ==Integer.parseInt(jtf.getText()) && GetSQL.pwd.equals(jpf.getText()))
        {
//                  System.out.println("Login Succeed!");
            JOptionPane.showMessageDialog(null,"Login Succeed!!","Message",JOptionPane.WARNING_MESSAGE);
            this.clear();
            //
            dispose();

            MEDICINE_UI ui=new MEDICINE_UI();
        }else if(jtf.getText().isEmpty()&&jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username and password!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jtf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter username!","Message",JOptionPane.WARNING_MESSAGE);
        }else if(jpf.getText().isEmpty())
        {
            JOptionPane.showMessageDialog(null,"Please enter password!","Message",JOptionPane.WARNING_MESSAGE);
        }else
        {
            JOptionPane.showMessageDialog(null,"username or password fails!\nplease enter again","Message",JOptionPane.ERROR_MESSAGE);
            //
            this.clear();
        }
    }




}

How the MySQL and JDBC interact will be shown in the following code. Basically, in the project it involves inserting, updating, deleting and selecting functions of SQL. The server is located in localhost PORT 3306, and using DriverManager we can easily connect to the SQL server and do our manipulations. By the fetching and matching, all the functions in this hospital database system can be done to eliminate the possibility of data redundancy and data inconsistency.

package Hospital;

/**
 * Created by maoyuanqi on 2017/12/4.
 */
import javax.swing.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * Created by maoyuanqi on 2017/12/2.
 */
class GetSQL
{
    //user name and password
    static int userword;
    static String pwd;

    static Connection ct=null;
    static PreparedStatement ps=null;
    static ResultSet rs=null;

    //hr-use
    static int username;
    static String Department;
    static String Position;
    static String Address;
    static String Name;
    //medicine-use
    static int mno;
    static int inventory;
    static int Price;
    static String medicine_Name;
    static String Vendor;
    static String Specification;
    static String Type;
    //financeq1-use
    static int[] pcno=new int[100];
    static String[] name=new String[100];
    static String[] position=new String[100];
    static int[] eNo=new int[100];
    static double[] Salary=new double[100];
    static double[] Bonus=new double[100];
    static String[] PayDate=new String[100];
    static int paycheck_count=0;
    //financeq2-use
    static int[] invoiceNo=new int[100];
    static String[] payment_name=new String[100];
    static double[] amount=new double[100];
    static String[] pay_method=new String[100];
    static String[] status=new String[100];
    static int[] payment_pNo=new int[100];
    static int payment_count=0;
    //clinic-use
    static int[] prescriptNo=new int[100];
    static int[] employeeNo=new int[100];
    static int[] patientNo=new int[100];
    static String[] Description=new String[100];
    static int history_count=0;

    //receptionist-use
    static int pNo;
    static double Money_Reserved;
    static String patient_Name;
    static String patient_Address;
    static int patient_Age;
    static String Gender;
    static String Phone;

    //medicine query 3
    static int prescript_no;
    static String description;
    static int Inventory;

    // recept query-user
    static String pati_name;
    static String pati_address;
    static int pati_age;
    static String pati_gender;
    static String pati_phone;





    //database connection, canbe inherited through sub-class.
    public static void ConnectSQL()
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            ct= DriverManager.getConnection("jdbc:mysql://localhost:3306/Hospital?","root","root");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    //login query
    public static void sqlquery(String s,int e_no)
    {
        //
        try {

            ps = ct.prepareStatement("select * from Employee where Department=? AND eNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setString(1, s);
            ps.setInt(2, e_no);
            //ResultSet
            rs=ps.executeQuery();
            //fetching by loop
            while(rs.next()){
                //pull out the username n password.
                userword=rs.getInt(1);
                pwd=rs.getString(6);
                System.out.println("Successfully Matched");
                System.out.println(userword+"\t"+pwd+"\t");
            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void hr_query(int s)
    {
        //
        try {

            ps = ct.prepareStatement("select * from Employee where eNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setInt(1, s);


            //ResultSet
            rs=ps.executeQuery();
            //fetching by loop
            while(rs.next()){
                //pull out the username n password.

                username=rs.getInt(1);
                Department=rs.getString(2);
                Position=rs.getString(3);
                Address=rs.getString(4);
                Name=rs.getString(5);


            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void medicine_query(int s)
    {
        //
        try {

            ps = ct.prepareStatement("select * from Medicine where mNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setInt(1, s);


            //ResultSet
            rs=ps.executeQuery();
            //fetching by loop
            while(rs.next()){
                //pull out the username n password.

                mno=rs.getInt(1);
                inventory=rs.getInt(2);
                Price=rs.getInt(3);
                medicine_Name=rs.getString(4);
                Vendor=rs.getString(5);
                Specification=rs.getString(6);
                Type=rs.getString(7);


            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void finance_query(int s)
    {
        //

        try {

            ps = ct.prepareStatement("select * from Paycheck where eNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setInt(1, s);


            //ResultSet
            rs=ps.executeQuery();
            //fetching by loop
            paycheck_count=0;
            while(rs.next()){
                //pull out the username n password.

                pcno[paycheck_count]=rs.getInt(1);
                name[paycheck_count]=rs.getString(2);
                position[paycheck_count]=rs.getString(3);
                eNo[paycheck_count]=rs.getInt(4);
                Salary[paycheck_count]=rs.getDouble(5);
                Bonus[paycheck_count]=rs.getDouble(6);
                PayDate[paycheck_count]=rs.getString(7);
                paycheck_count++;
//                inventory=rs.getInt(2);
//                Price=rs.getInt(3);
//                medicine_Name=rs.getString(4);
//                Vendor=rs.getString(5);
//                Specification=rs.getString(6);
//                Type=rs.getString(7);


            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void finance_query2(int s)
{
    //
    try {

        ps = ct.prepareStatement("select * from payment where pNo=?");
        // ?should be filled with a value, this way is much safer.
        ps.setInt(1, s);


        //ResultSet
        rs=ps.executeQuery();
        payment_count=0;
        //fetching by loop
        while(rs.next()){
            //pull out the username n password.

            invoiceNo[payment_count]=rs.getInt(1);
            payment_name[payment_count]=rs.getString(2);
            amount[payment_count]=rs.getDouble(3);
            pay_method[payment_count]=rs.getString(4);
            status[payment_count]=rs.getString(5);
            payment_pNo[payment_count]=rs.getInt(6);
            payment_count++;




        }
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
    }
}
    public static void Receptionist_query(int s)
    {
        //
        try {

            ps = ct.prepareStatement("select * from patient where pNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setInt(1, s);


            //ResultSet
            rs=ps.executeQuery();
            //fetching by loop
            while(rs.next()){
                //pull out the username n password.

                pNo=rs.getInt(1);
                Money_Reserved=rs.getDouble(2);
                patient_Name=rs.getString(3);
                patient_Address=rs.getString(4);
                patient_Age=rs.getInt(5);
                Gender=rs.getString(6);
                Phone=rs.getString(7);


            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }
    public static void clinic_query(int s)
    {
        //
        try {

            ps = ct.prepareStatement("select * from Prescription where pNo=?");
            // ?should be filled with a value, this way is much safer.
            ps.setInt(1, s);


            //ResultSet
            rs=ps.executeQuery();
            history_count=0;
            //fetching by loop
            while(rs.next()){
                //pull out the username n password.

                prescriptNo[history_count]=rs.getInt(1);
                employeeNo[history_count]=rs.getInt(2);
                patientNo[history_count]=rs.getInt(3);
                Description[history_count]=rs.getString(4);
                history_count++;


            }
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void clinic_query2(int empNo,int pNo,String description)
    {
        //
        try {

            ps = ct.prepareStatement("insert into Prescription(eNo,pNo,Description) values (?,?,?)");
            // ?should be filled with a value, this way is much safer.
           // ps.setInt(1, psNo);
            ps.setInt(1, empNo);
            ps.setInt(2, pNo);
            ps.setString(3, description);


            //ResultSet
            ps.execute();
            System.out.println("Successfully inserted");
            JOptionPane.showMessageDialog(null, "Insert Success!", "Warning", JOptionPane.WARNING_MESSAGE);


            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void medicine_plus(int medicineNo,String quantity)
    {
        //
        try {
            int q = Integer.parseInt(quantity);
            ps = ct.prepareStatement("update Medicine set Inventory = Inventory + ? where mNo = ?");
            // ?should be filled with a value, this way is much safer.

            ps.setInt(1,q);
            ps.setInt(2, medicineNo);


            //ResultSet
            ps.execute();
            System.out.println("Successfully modified");
            JOptionPane.showMessageDialog(null, "Modification Success!", "Warning", JOptionPane.WARNING_MESSAGE);


            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }
    public static void medicine_minus(int medicineNo,String quantity)
    {
        //
        try {
            int q = Integer.parseInt(quantity);
            ps = ct.prepareStatement("update Medicine set Inventory = Inventory - ? where mNo = ?");
            // ?should be filled with a value, this way is much safer.

            ps.setInt(1,q);
            ps.setInt(2, medicineNo);


            //ResultSet
            ps.execute();
            System.out.println("Successfully modified");
            JOptionPane.showMessageDialog(null, "Modification Success!", "Warning", JOptionPane.WARNING_MESSAGE);




            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void medicine_query3(int prescriptionNo)
    {
        //
        try {

            ps = ct.prepareStatement("select prescription_No, Description from Prescription where prescription_No = ? ");
            // ?should be filled with a value, this way is much safer.

            ps.setInt(1, prescriptionNo);



            //ResultSet
            rs=ps.executeQuery();
            while(rs.next()){
                //pull out the username n password.

                prescript_no=rs.getInt(1);
                description =  rs.getString(2);


            }

            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();               JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void recept_query(String name, String address,int age, String gender, String phone)
    {
        //
        try {

            ps = ct.prepareStatement("insert into patient(Money_Reserved,Name,Address,Age,Gender,Phone) values (0,?,?,?,?,?)");
            // ?should be filled with a value, this way is much safer.
            // ps.setInt(1, psNo);
            ps.setString(1, name);
            ps.setString(2, address);
            ps.setInt(3, age);
            ps.setString(4, gender);
            ps.setString(5, phone);



            //ResultSet
            ps.execute();
            System.out.println("Successfully inserted");
            JOptionPane.showMessageDialog(null, "Insert Success!", "Warning", JOptionPane.WARNING_MESSAGE);


            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

    public static void hr_query1(String department, String position,String address,String name, String password)
    {
        //
        try {

            ps = ct.prepareStatement("insert into Employee(Department,Position,Address,Name,Password) values (?,?,?,?,?)");
            // ?should be filled with a value, this way is much safer.
            // ps.setInt(1, psNo);
            ps.setString(1, department);
            ps.setString(2, position);
            ps.setString(3, address);
            ps.setString(4, name);
            ps.setString(5, password);



            //ResultSet
            ps.execute();
            System.out.println("Successfully inserted");
            JOptionPane.showMessageDialog(null, "Insert Success!", "Warning", JOptionPane.WARNING_MESSAGE);


            //fetching by loop
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);                     JOptionPane.showMessageDialog(null, "Execution failed!", "Warning", JOptionPane.WARNING_MESSAGE);
        }
    }

}
Here I will not upload with specific functions inside the database in order to prevent malicious usage. Basically, this project is to practice my skill at operating MySQL and JDBC. Also, through this, I feel like it's very much necessary to maintain the database in a big company, especially when the data is important. Otherwise, the overwhelming data size will crush the whole company down.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值