基于java+mysql的swing+mysql人力管理系统(java+gui)

基于java+mysql的swing+mysql人力管理系统(java+gui)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于java+mysql的Swing+MySQL人力管理系统(java+gui)

功能介绍:

角色员工、管理员,员工信息表,查询、更新,修改,移除、添加

		}
		System.out.println("jCBSelectQueryFieldTransfer(). outputStr = " + outputStr);
		return outputStr;
	}

}

public class DatabaseCourseDesign extends JFrame implements ActionListener {
	// 定义组件
	// 此定义方法先记住
	JLabel jLStudentInfoTable = null;// 学生信息表
	JLabel jLSelectQueryField = null;// 选择查询字段
	JLabel jLEqual = null;// =
	JLabel jLSNo = null;// 学号
	JLabel jLSName = null;// 姓名
	JLabel jLSSex = null;// 性别
	JLabel jLSAge = null;// 年龄
	JLabel jLSSpecialty = null;// 专业
	JLabel jLSAddress = null;// 住址

	JTextField jTFQueryField = null;// 查询字段
	JTextField jTFSNo = null;// 学号
	JTextField jTFSName = null;// 姓名
	JTextField jTFSSex = null;// 性别
	JTextField jTFSAge = null;// 年龄
	JTextField jTFSSpecialty = null;// 专业
	JTextField jTFSAddress = null;// 住址

	JButton jBQuery = null;// 查询
	JButton jBQueryAll = null;// 查询所有记录
	JButton jBInsert = null;// 插入
    String userMySql = "root";
    String passwordMySql = "123456";

    // 构造函数
    public DbProcess() {
        try {
            // mysql数据库设置驱动程序类型
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("mysql数据库驱动加载成功");

            // sqlserver数据库设置驱动程序类型
            // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            // System.out.println("sqlserver数据库驱动加载成功");

        } catch (java.lang.ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void connect() {
        try {
            // mysql数据库
            connection = DriverManager.getConnection(urlMySql, userMySql, passwordMySql);

            // sqlserver数据库
            // connection = DriverManager.getConnection(urlSqlServer);

            if (connection != null) {
                System.out.println("数据库连接成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void disconnect() {// 断开连接
        try {
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public ResultSet executeQuery(String sql) {/// sql为完整符合mysql语法的数据库查询语句
        try {
            System.out.println("executeQuery(). sql = " + sql);

            PreparedStatement pstm = connection.prepareStatement(sql);
				} catch (SQLException sqle) {
					System.out.println("sqle = " + sqle);
					JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
				}
			} // 管理员框被选中

		}

	}// actionPerformed
}

public class DbProcess {
    public static String imageIcon = "C:\\Users\\joey\\Desktop\\441222052008\\project\\src\\timg2.jpg";
    Connection connection = null;
    ResultSet rs = null;

    // mysql数据库url
    String urlMySql = "jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull";
    String userMySql = "root";
    String passwordMySql = "123456";

    // 构造函数
    public DbProcess() {
        try {
            // mysql数据库设置驱动程序类型
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("mysql数据库驱动加载成功");

            // sqlserver数据库设置驱动程序类型
            // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            // System.out.println("sqlserver数据库驱动加载成功");

        } catch (java.lang.ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void connect() {
			// 建立查询条件
			String sql = "select * from student;";
			System.out.println("queryAllProcess(). sql = " + sql);

			dbProcess.connect();
			ResultSet rs = dbProcess.executeQuery(sql);

			// 将查询获得的记录数据,转换成适合生成JTable的数据形式
			studentVector.clear();
			while (rs.next()) {
				Vector v = new Vector();
				v.add(rs.getString("sNo"));
				v.add(rs.getString("sName"));
				v.add(rs.getString("sSex"));
				v.add(Integer.valueOf(rs.getInt("sAge")));
				v.add(rs.getString("sSpecialty"));
				v.add(rs.getString("sAddress"));
				studentVector.add(v);
			}

			studentJTable.updateUI();

			dbProcess.disconnect();
		} catch (SQLException sqle) {
			System.out.println("sqle = " + sqle);
			JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
		}
	}

	public void insertProcess() {
		String sNo = jTFSNo.getText().trim();
		String sName = jTFSName.getText().trim();
		String sSex = jTFSSex.getText().trim();
		String sAge = jTFSAge.getText().trim();
		String sSpecialty = jTFSSpecialty.getText().trim();
		String sAddress = jTFSAddress.getText().trim();

		// 建立插入条件
		String sql = "insert into student values('";
		sql = sql + sNo + "','";
		sql = sql + sName + "','";
		sql = sql + sSex + "',";
		sql = sql + sAge + ",'";
		sql = sql + sSpecialty + "','";
		sql = sql + sAddress + "');";

		System.out.println("insertProcess(). sql = " + sql);
		try {
        } catch (SQLException ex) {
            System.err.println(ex.getMessage());
        }
        disconnect();
        return count;
    }

    public static void main(String args[]) {
        DbProcess dbprocess = new DbProcess();
        dbprocess.connect();
    }
}

public class change_password extends JFrame implements ActionListener {
	// 定义组件
	JLabel jLNewPassword = null; // 新密码
	JLabel jLNewPasswordAgain = null; // 再次输入新密码

	JTextField jTFNewPassword = null; // 新密码
	JTextField jTFNewPasswordAgain = null; // 再次输入新密码

	JButton jBEnsure = null;// 确认

	JPanel jP1, jP2, jP3 = null;
	public static DbProcess dbProcess;

	public change_password() {
		jLNewPassword = new JLabel("  新     密     码      ");
		jLNewPasswordAgain = new JLabel("再次输入新密码");
		jTFNewPassword = new JTextField(10);
		jTFNewPasswordAgain = new JTextField(10);
		jBEnsure = new JButton("确认");
		jBEnsure.addActionListener(this);

		jP1 = new JPanel();
		jP2 = new JPanel();
		jP3 = new JPanel();

		jP1.add(jLNewPassword);
		jP1.add(jTFNewPassword);
		jP2.add(jLNewPasswordAgain);
            // mysql数据库
            connection = DriverManager.getConnection(urlMySql, userMySql, passwordMySql);

            // sqlserver数据库
            // connection = DriverManager.getConnection(urlSqlServer);

            if (connection != null) {
                System.out.println("数据库连接成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void disconnect() {// 断开连接
        try {
            if (connection != null) {
                connection.close();
                connection = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public ResultSet executeQuery(String sql) {/// sql为完整符合mysql语法的数据库查询语句
        try {
            System.out.println("executeQuery(). sql = " + sql);

            PreparedStatement pstm = connection.prepareStatement(sql);
            // 执行查询
            rs = pstm.executeQuery();
            // 查询结果
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return rs;
    }

    // 插入
    // executeUpdate 的返回值是一个整数,指示受影响的行数(即更新计数)。
    // executeUpdate用于执行 INSERT、UPDATE 或 DELETE 语句
    // 以及 SQL DDL(数据定义语言)语句,例如 CREATE TABLE 和 DROP TABLE。

    // 执行增、删、改语句的方法
    public int executeUpdate(String sql) {
        int count = 0;
        connect();
        try {
            Statement stmt = connection.createStatement();
            count = stmt.executeUpdate(sql);
        } catch (SQLException ex) {
						res = rs.getString("PASSWD");
					}

					dbProcess.disconnect();
					if (jTFPassword.getText().equals(res))// 输入密码正确
					{// 保存账号和密码
						username = jTFUserName.getText();
						passwd = jTFPassword.getText();
						System.out.println("actionPerformed(). 用户登录成功");
						new main_screen();
					} else {// 密码错误登录失败
						new login_failure();
					}

				} catch (SQLException sqle) {
					System.out.println("sqle = " + sqle);
					JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
				}
			} // 管理员框被选中

		}

	}// actionPerformed
}

public class DbProcess {
    public static String imageIcon = "C:\\Users\\joey\\Desktop\\441222052008\\project\\src\\timg2.jpg";
    Connection connection = null;
    ResultSet rs = null;

    // mysql数据库url
    String urlMySql = "jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull";
    String userMySql = "root";
    String passwordMySql = "123456";

    // 构造函数
    public DbProcess() {
        try {
            // mysql数据库设置驱动程序类型
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("mysql数据库驱动加载成功");

            // sqlserver数据库设置驱动程序类型
            // Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            // System.out.println("sqlserver数据库驱动加载成功");

        } catch (java.lang.ClassNotFoundException e) {
            e.printStackTrace();
        }
	JLabel JTFTips = null;// 提示

	JPanel jP1, jP2;

	public login_failure() {
		// 构造函数
		JBGoBack = new JButton("返回");
		JTFTips = new JLabel("密码或账号输入有误,请重新输入!");

		JBGoBack.addActionListener(this);
		this.add(JTFTips);
		this.add(JBGoBack);

		this.setSize(250, 125);
		this.setLocation(700, 200);
		this.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
	}

	public void actionPerformed(ActionEvent e) {
		this.dispose();// 关闭窗口
	}
}

public class login extends JFrame implements ActionListener {// 登录界面加一张图片
	static String username = null;// 用户名
	static String passwd = null;// 密码
	// 定义组件
	// 标签
	JLabel jLHRManagement = null;// 人事管理系统
	JLabel jLUserName = null;// 用户名
	JLabel jLPassword = null;// 密码
	JLabel jLStatus = null;// 身份
	JLabel jLImage = null;// 图片
	ImageIcon icon = null;// 插图

	// 文本
	JTextField jTFUserName = null;// 用户名文本框
	JPasswordField jTFPassword = null;// 密码文本框 保密的

	// 按钮
	JButton jBLogin = null;// 登录
	JButton jBQuit = null;// 退出

	private static DbProcess dbProcess;
	String SelectQueryFieldStr = "学号";

	// 构造函数
	public DatabaseCourseDesign() {
		// 创建组件
		jLStudentInfoTable = new JLabel("学生信息表");
		jLSelectQueryField = new JLabel("选择查询字段");
		jLEqual = new JLabel(" = ");
		jLSNo = new JLabel("学号");
		jLSName = new JLabel("姓名");
		jLSSex = new JLabel("性别");
		jLSAge = new JLabel("年龄");
		jLSSpecialty = new JLabel("专业");
		jLSAddress = new JLabel("住址");

		jTFQueryField = new JTextField(10);// 查询字段
		jTFSNo = new JTextField(10);// 学号
		jTFSName = new JTextField(10);// 姓名
		jTFSSex = new JTextField(10);// 性别
		jTFSAge = new JTextField(10);// 年龄
		jTFSSpecialty = new JTextField(10);// 专业
		jTFSAddress = new JTextField(10);// 住址

		jBQuery = new JButton("查询");
		jBQueryAll = new JButton("查询所有记录");
		jBInsert = new JButton("插入");
		jBUpdate = new JButton("更新");
		jBDeleteCurrentRecord = new JButton("删除当前记录");
		jBDeleteAllRecords = new JButton("删除所有记录");
		// 设置监听
		// this关键字代指类DatabaseCourseDesigned,实现了ActionListener接口
		jBQuery.addActionListener(this);
		jBQueryAll.addActionListener(this);
		jBInsert.addActionListener(this);
		jBUpdate.addActionListener(this);
		jBDeleteCurrentRecord.addActionListener(this);
		jBDeleteAllRecords.addActionListener(this);

		jCBSelectQueryField = new JComboBox<String>();// 查询字段
			insertProcess();
		} else if (e.getActionCommand().equals("更新") && !jTFID.getText().isEmpty() && !jTFAuthority.getText().isEmpty()
				&& !jTFName.getText().isEmpty() && !jTFSex.getText().isEmpty() && !jTFBirthday.getText().isEmpty()
				&& !jTFDepartment.getText().isEmpty() && !jTFJob.getText().isEmpty()
				&& !jTFEdu_Level.getText().isEmpty() && !jTFSpcialty.getText().isEmpty()
				&& !jTFAddress.getText().isEmpty() && !jTFTEL.getText().isEmpty() && !jTFEmail.getText().isEmpty()
				&& !jTFState.getText().isEmpty() && !jTFRemark.getText().isEmpty()) {
			System.out.println("actionPerformed(). 更新");
			updateProcess();
		} else if (e.getActionCommand().equals("删除当前员工")) {
			System.out.println("actionPerformed(). 删除当前员工");
			deleteCurrentRecordProcess();
		} else if (e.getActionCommand().equals("查看人事变动")) {
			new person_change();
		} else if (e.getActionCommand().equals("修改密码")) {
			new change_password();
		}
	}

	public static void main(String[] args) {
		new main_screen();
	}

	public void queryProcess(String sQueryField)
	{
		try {
			// 建立查询条件
			String sql = "select * from person where ";
			String queryFieldStr = jCBSelectQueryFieldTransfer(SelectQueryFieldStr);// 翻译查询依据,如"员工号"翻译为"ID"
			sql = sql + queryFieldStr;
			sql = sql + " = ";
			sql = sql + "'" + sQueryField + "';";

			System.out.println("queryProcess(). sql = " + sql);

			dbProcess.connect();
			ResultSet rs = dbProcess.executeQuery(sql);

			// 将查询获得的记录数据,转换成适合生成JTable的数据形式
			EmployeeVector.clear();// 清空原先数据
			while (rs.next()) {
				Vector v = new Vector();
				v.add(rs.getString("ID"));
				v.add(rs.getString("AUTHORITY"));
				v.add(rs.getString("NAME"));
				v.add(rs.getString("SEX"));
				System.out.println("updateProcess(). update database failed.");
			}
		} catch (Exception e) {
			System.out.println("e = " + e);
			JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
		}
		queryProcess(ID);
	}

}

public class person_change extends JFrame implements ActionListener {// 人事变动表
	// 添加组件
	JLabel jLPersonChange = null;// 人事变动表
	JLabel jLPerson = null;// 员工号
	JLabel jLEqual = null;// =
	JLabel jLImage = null;// 插图
	ImageIcon icon = null;// 插图

	JTextField jTFQueryField = null;// 查询某人
	JTextField jTFID = null;// 记录编号
	JTextField jTFPerson = null;// 员工号
	JTextField jTFChange = null;// 变更代码
	JTextField jTFDiscription = null;// 详细记录

	JButton jBQuery = null;// 查询某人
	JButton jBQueryAll = null;// 查询所有

	JPanel jP1, jP2, jP3 = null;

	DefaultTableModel PersonChangeTableModel = null;
	JTable PersonChangeJTable = null;
	JScrollPane PersonChangeJScrollPane = null;
	Vector PersonChangeVector = null;
	Vector titleVector = null;

	private static DbProcess dbProcess = null;

	public person_change() {// 构造函数
		jBDeleteCurrentRecord.addActionListener(this);
		jBDeleteAllRecords.addActionListener(this);

		jCBSelectQueryField = new JComboBox<String>();// 查询字段
		jCBSelectQueryField.addItem("学号");
		jCBSelectQueryField.addItem("姓名");
		jCBSelectQueryField.addItem("性别");
		jCBSelectQueryField.addItem("年龄");
		jCBSelectQueryField.addItem("专业");
		jCBSelectQueryField.addItem("住址");
		jCBSelectQueryField.addItemListener(new ItemListener() {// 下拉框事件监听
			// 匿名内部类实现接口并作为参数传入
			// ItemListener监听器 待会再来理解
			public void itemStateChanged(ItemEvent event) {
				switch (event.getStateChange()) {
				case ItemEvent.SELECTED:
					SelectQueryFieldStr = (String) event.getItem();
					System.out.println("选中:" + SelectQueryFieldStr);
					break;
				case ItemEvent.DESELECTED:
					System.out.println("取消选中:" + event.getItem());
					break;
				}
			}
		});

		studentVector = new Vector();
		titleVector = new Vector();

		// 定义表头
		// 单列矩阵
		// JTable:表格这一段还不太理解
		titleVector.add("学号");
		titleVector.add("姓名");
		titleVector.add("性别");
		titleVector.add("年龄");
		titleVector.add("专业");
		titleVector.add("住址");
		// studentTableModel = new DefaultTableModel(tableTitle, 15);
		studentJTable = new JTable(studentVector, titleVector);
		studentJTable.setPreferredScrollableViewportSize(new Dimension(450, 160));
		studentJScrollPane = new JScrollPane(studentJTable);
		// 分别设置水平和垂直滚动条自动出现
		studentJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		studentJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

		// 为表格添加监听器
		studentJTable.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置
		// 分别设置水平和垂直滚动条自动出现
		PersonChangeJScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		PersonChangeJScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

		// 为表格添加监听器
		PersonChangeJTable.addMouseListener(new MouseAdapter() {
			public void mouseClicked(MouseEvent e) {
				int row = ((JTable) e.getSource()).rowAtPoint(e.getPoint()); // 获得行位置
				System.out.println("mouseClicked(). row = " + row);
				Vector v = new Vector();
				v = (Vector) PersonChangeVector.get(row);

				jTFID.setText((String) v.get(0));// 记录编号
				jTFPerson.setText((String) v.get(1));// 员工号
				jTFChange.setText((String) v.get(2));// 变更代码
				jTFDiscription.setText((String) v.get(3));// 详细记录
			}
		});

		jP1 = new JPanel();
		jP2 = new JPanel();
		jP3 = new JPanel();

		jP1.add(jLPersonChange);
		jP2.add(PersonChangeJScrollPane);
		jP3.add(jLPerson);
		jP3.add(jLEqual);
		jP3.add(jTFQueryField);
		jP3.add(jBQuery);
		jP3.add(jBQueryAll);

		this.add(jP1);
		this.add(jP2);
		this.add(jP3);

		this.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.setTitle(login.username + "--");
		this.setSize(500, 500);
		this.setLocation(800, 200);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
		dbProcess = new DbProcess();
}

public class employee_view extends JFrame implements ActionListener {// 通过文本框是否可编辑来操控用户更新权限
	// 定义组件
	JButton jBQuery = null;// 查询个人信息
	JButton jBUpdate = null;// 更新
	JPanel jP1, jP2, jP3, jP4, jP5, jP6, jP7, jP8, jP9, jP10, jP11, jP12, jP13, jP14, jP15, jP16;

	static JTextField jTFID = new JTextField(10); // 员工号
	static JTextField jTFPassword = new JTextField(10); // 密码
	static JTextField jTFAuthority = new JTextField(10); // 用户权限
	static JTextField jTFName = new JTextField(10); // 姓名
	static JTextField jTFSex = new JTextField(10); // 性别
	static JTextField jTFBirthday = new JTextField(10); // 生日
	static JTextField jTFDepartment = new JTextField(10); // 所在部门
	static JTextField jTFJob = new JTextField(10); // 职务
	static JTextField jTFEdu_Level = new JTextField(10); // 受教育程度
	static JTextField jTFSpcialty = new JTextField(10); // 专业技能
	static JTextField jTFAddress = new JTextField(10); // 家庭住址
	static JTextField jTFTEL = new JTextField(10); // 联系电话
	static JTextField jTFEmail = new JTextField(10); // 电子邮箱
	static JTextField jTFState = new JTextField(10); // 当前状态(T-员工、F-非员工)
	static JTextField jTFRemark = new JTextField(10); // 备注

	private static DbProcess dbProcess;

	// 构造函数
	public employee_view() {
		JLabel jLID = new JLabel(" 员   工   号 "); // 员工号
		JLabel jLPassword = new JLabel(" 密          码 "); // 密码
		JLabel jLAuthority = new JLabel("用 户 权 限"); // 用户权限
		JLabel jLName = new JLabel(" 姓          名 "); // 姓名
		JLabel jLSex = new JLabel(" 性          别 "); // 性别
		JLabel jLBirthday = new JLabel(" 生          日 "); // 生日
		JLabel jLDepartment = new JLabel(" 所 在 部 门"); // 所在部门
		JLabel jLJob = new JLabel(" 职          务 "); // 职务
		this.dispose();

	}

}

public class DbProcess {
    Connection connection = null;
    ResultSet rs = null;

    // mysql数据库url
    String urlMySql = "jdbc:mysql://localhost:3306/project?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&autoReconnect=true&failOverReadOnly=false&allowPublicKeyRetrieval=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull";
    String userMySql = "root";
    String passwordMySql = "123456";

    // 构造函数
    public DbProcess() {
        try {
            // mysql数据库设置驱动程序类型
            Class.forName("com.mysql.jdbc.Driver");
            System.out.println("mysql数据库驱动加载成功");

        } catch (java.lang.ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public void connect() {
        try {
            // mysql数据库
            connection = DriverManager.getConnection(urlMySql, userMySql, passwordMySql);

            if (connection != null) {
                System.out.println("数据库连接成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void disconnect() {// 断开连接
        try {
            if (connection != null) {
		jLImage = new JLabel(icon);

		jP1 = new JPanel();
		jP2 = new JPanel();
		jP3 = new JPanel();
		jP4 = new JPanel();
		jP5 = new JPanel();

		// jP1.add(jLHRManagement);
		jP1.add(jLImage);
		jP2.add(jLUserName);
		jP2.add(jTFUserName);
		jP2.add(jLPassword);
		jP2.add(jTFPassword);
		jP3.add(jRBEmployee);
		jP3.add(jRBManager);
		jP3.add(jBLogin);
		jP3.add(jBQuit);

		this.add(jP1);
		this.add(jP2);
		this.add(jP3);

		this.setLayout(new FlowLayout(FlowLayout.CENTER));
		this.setTitle("人事管理登录界面");
		this.setSize(500, 600);
		this.setLocation(700, 200);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
		dbProcess = new DbProcess();// 数据库驱动

	}

	// 主方法
	public static void main(String[] args) {
		new login();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// 监听器
		// 用户退出
		if (e.getActionCommand().equals("退出")) {
			System.out.println("actionPerformed(). 用户退出");
			this.setVisible(false);
		String DEPARTMENT = jTFDepartment.getText().trim();
		String JOB = jTFJob.getText().trim();
		String EDU_LEVEL = jTFEdu_Level.getText().trim();
		String SPCIALTY = jTFSpcialty.getText().trim();
		String ADDRESS = jTFAddress.getText().trim();
		String TEL = jTFTEL.getText().trim();
		String EMAIL = jTFEmail.getText().trim();
		String STATE = jTFState.getText().trim();
		String REMARK = jTFRemark.getText().trim();
		// 建立插入条件
		String sql = "insert into person values('";
		sql = sql + ID + "','";
		sql = sql + ID + "','";// 密码初始化与员工号相同
		sql = sql + AUTHORITY + "','";
		sql = sql + NAME + "','";
		sql = sql + SEX + "','";
		sql = sql + BIRTHDAY + "','";
		sql = sql + DEPARTMENT + "','";
		sql = sql + JOB + "','";
		sql = sql + EDU_LEVEL + "','";
		sql = sql + SPCIALTY + "','";
		sql = sql + ADDRESS + "','";
		sql = sql + TEL + "','";
		sql = sql + EMAIL + "','";
		sql = sql + STATE + "','";
		sql = sql + REMARK + "');";

		System.out.println("insertProcess(). sql = " + sql);
		try {
			if (dbProcess.executeUpdate(sql) < 1) {
				System.out.println("insertProcess(). insert database failed.");
			}
		} catch (Exception e) {
			System.out.println("e = " + e);
			JOptionPane.showMessageDialog(null, "数据操作错误", "错误", JOptionPane.ERROR_MESSAGE);
		}
		queryAllProcess();
	}

	public void updateProcess() {
		String ID = jTFID.getText().trim();
		String AUTHORITY = jTFAuthority.getText().trim();

请添加图片描述

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,为了实现基于Java+Swing+MySQL的汽车租赁管理系统,我们需要进行以下几个步骤: 1. 创建MySQL数据库并设计表结构,包括车辆信息表、客户信息表、订单信息表等。 2. 使用Java JDBC连接MySQL数据库,编写Java代码来实现数据的增删改查等基本操作。 3. 使用Swing GUI框架设计系统的用户界面,包括登录界面、主界面、车辆信息管理界面、客户信息管理界面、订单信息管理界面等。 4. 将Java代码和MySQL数据库连接起来,实现系统的功能,例如车辆信息的添加、查询、修改、删除,客户信息的添加、查询、修改、删除等。 5. 针对不同的用户权限,设置不同的操作权限,例如管理员可以对系统进行管理,普通用户只能进行车辆租赁等操作。 6. 对系统进行测试和调试,确保系统稳定性和安全性。 这里提供一个简单的代码示例,用于连接MySQL数据库并进行查询操作: ``` import java.sql.*; public class Demo { public static void main(String[] args) { try { // 驱动程序名 String driver = "com.mysql.jdbc.Driver"; // 数据库URL String url = "jdbc:mysql://localhost:3306/test"; // 数据库用户名 String user = "root"; // 数据库密码 String password = "123456"; // 加载驱动程序 Class.forName(driver); // 连接数据库 Connection conn = DriverManager.getConnection(url, user, password); // 创建Statement对象 Statement stmt = conn.createStatement(); // 查询操作 String sql = "SELECT * FROM user"; ResultSet rs = stmt.executeQuery(sql); // 处理结果集 while(rs.next()){ System.out.println(rs.getString("name")); } // 关闭结果集、Statement和连接 rs.close(); stmt.close(); conn.close(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } } } ``` 此外,还需要编写Swing GUI界面和其他相关代码来实现完整的汽车租赁管理系统

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值