目錄
開發工具:Eclipse2021
JDK版本:jdk1.8
Mysql版本:8.0.13
Java+Swing+Mysql
1.管理員登入系統;
2.管理員查詢員工資訊,增加員工資訊,修改員工資訊,刪除員工資訊;
3.管理員查詢部門資訊,增加部門資訊,修改部門資訊,刪除部門資訊;
4.管理員查詢職務資訊,增加職務資訊,修改職務資訊,刪除職務資訊;
/*
Navicat Premium Data Transfer
Source Server : MySQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : 127.0.0.1:3306
Source Schema : swing_staff_management
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 07/01/2022 21:39:20
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for dept
-- ----------------------------
DROP TABLE IF EXISTS `dept`;
CREATE TABLE `dept` (
`num` int(11) NULL DEFAULT NULL,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '部門名稱',
`address` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of dept
-- ----------------------------
INSERT INTO `dept` VALUES (101, '巨量資料部', '一樓');
INSERT INTO `dept` VALUES (102, '人力行政部', '二樓');
INSERT INTO `dept` VALUES (103, '後勤部', '三樓');
-- ----------------------------
-- Table structure for duty
-- ----------------------------
DROP TABLE IF EXISTS `duty`;
CREATE TABLE `duty` (
`num` int(4) NOT NULL COMMENT '職務名稱',
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`low` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`high` varchar(10) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of duty
-- ----------------------------
INSERT INTO `duty` VALUES (111, '職員', '10000', '20000');
INSERT INTO `duty` VALUES (112, '科長', '20000', '40000');
INSERT INTO `duty` VALUES (113, '部長', '40000', '60000');
INSERT INTO `duty` VALUES (114, '總監', '60000', '80000');
INSERT INTO `duty` VALUES (115, '總經理', '100000', '150000');
-- ----------------------------
-- Table structure for login
-- ----------------------------
DROP TABLE IF EXISTS `login`;
CREATE TABLE `login` (
`id` decimal(4, 0) NOT NULL,
`username` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`password` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of login
-- ----------------------------
INSERT INTO `login` VALUES (1, 'admin', 'admin');
-- ----------------------------
-- Table structure for staff
-- ----------------------------
DROP TABLE IF EXISTS `staff`;
CREATE TABLE `staff` (
`num` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
`name` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`sex` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`salary` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`phone` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`dept` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
`duty` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
PRIMARY KEY (`num`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of staff
-- ----------------------------
INSERT INTO `staff` VALUES ('1001', '張三', '男', '50000', '13332259632', '巨量資料部', '部長');
INSERT INTO `staff` VALUES ('1002', '李四', '男', '30000', '13332259632', '巨量資料部', '科長');
INSERT INTO `staff` VALUES ('1003', '王五', '男', '20000', '13332259632', '後勤部', '職員');
SET FOREIGN_KEY_CHECKS = 1;
package dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import utils.DBUtil;
import vo.Admin;
public class AdminDao {
// 判斷有無此使用者
public static boolean isUser(Admin admin) {
String sql = "select * from login where username=? and password = ?";
ResultSet rs;
// 定義陣列用來存放賬號和密碼
String[] adminString = new String[] {admin.getUserName(), admin.getPassword()};
try {
rs = DBUtil.execQuery(sql, adminString);
if (rs.next())
return true;
else
return false;
} catch (SQLException e) {
e.printStackTrace();
return false;
} finally {
DBUtil.close();
}
}
// 測試
public static void main(String[] args) {
Admin admin = new Admin();
admin.setUserName("admin");
admin.setPassword("admin");
boolean flag = isUser(admin);
System.out.println(flag);
}
}
package dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import utils.DBUtil;
import utils.SqlHelper;
import vo.Dept;
/**
*
* 部門管理
*
*/
public class DeptDao {
static public int update(Dept dept, int flag) throws SQLException {
int result = -1;
String sqlCondition[] = null;
try {
switch (flag) {
case SqlHelper.INSERT:
sqlCondition = new String[] { dept.getNum(), dept.getName(), dept.getAddress() };
break;
case SqlHelper.DELETE:
sqlCondition = new String[] { dept.getNum() };
break;
case SqlHelper.UPDATE:
sqlCondition = new String[] { dept.getName(), dept.getAddress(), dept.getNum() };
break;
}
result = DBUtil.execUpdate(SqlHelper.DeptSqls[flag], sqlCondition);
return result;
} catch (SQLException e) {
} finally {
DBUtil.close();
}
return result;
}
static public Dept query(final Dept dept) throws SQLException {
ResultSet rs;
try {
rs = DBUtil.execQuery("select * from dept where num=?", new String[] { dept.getNum() });
if (rs.next()) {
dept.setName(rs.getString("name"));
dept.setAddress(rs.getString("address"));
System.out.println("查到該資料");
} else {
System.out.println("沒有查到該資料");
return null;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} finally {
DBUtil.close();
}
return dept;
}
}
package dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import utils.DBUtil;
import utils.SqlHelper;
import vo.Duty;
/**
*
* 職務管理
*
*/
public class DutyDao {
static public int update(Duty duty, int flag) throws SQLException {
int result = -1;
String sqlCondition[] = null;
try {
switch (flag) {
case SqlHelper.INSERT:
sqlCondition = new String[] { duty.getNum(), duty.getName(), duty.getLow(), duty.getHigh() };
break;
case SqlHelper.DELETE:
sqlCondition = new String[] { duty.getNum() };
break;
case SqlHelper.UPDATE:
sqlCondition = new String[] { duty.getName(), duty.getLow(), duty.getHigh(), duty.getNum() };
break;
}
result = DBUtil.execUpdate(SqlHelper.DutySqls[flag], sqlCondition);
return result;
} catch (SQLException e) {
} finally {
DBUtil.close();
}
return result;
}
static public Duty query(final Duty duty) throws SQLException {
ResultSet rs;
try {
rs = DBUtil.execQuery("select * from duty where num=?", new String[] { duty.getNum() });
if (rs.next()) {
duty.setNum(rs.getString("num"));
duty.setName(rs.getString("name"));
duty.setLow(rs.getString("low"));
duty.setHigh(rs.getString("high"));
System.out.println("查到該資料");
} else {
System.out.println("沒有查到該資料");
return null;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} finally {
DBUtil.close();
}
return duty;
}
}
package dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import utils.DBUtil;
import utils.SqlHelper;
import vo.Staff;
/**
*
* 職員管理
*
*/
public class StaffDao {
static public int update(Staff staff, int flag) throws SQLException {
int result = -1;
String sqlCondition[] = null;
try {
switch (flag) {
case SqlHelper.INSERT:
sqlCondition = new String[] { staff.getNum(), staff.getName(),
staff.getSex(), staff.getSalary(), staff.getPhone(),
staff.getDept(), staff.getDuty() };
break;
case SqlHelper.DELETE:
sqlCondition = new String[] { staff.getNum() };
break;
case SqlHelper.UPDATE:
sqlCondition = new String[] { staff.getName(), staff.getSex(),
staff.getSalary(), staff.getPhone(), staff.getDept(),
staff.getDuty(), staff.getNum() };
break;
}
result = DBUtil.execUpdate(SqlHelper.StaffSqls[flag],
sqlCondition);
return result;
} catch (SQLException e) {
} finally {
DBUtil.close();
}
return result;
}
static public Staff query(final Staff staff) throws SQLException {
ResultSet rs;
try {
rs = DBUtil.execQuery("select * from staff where num=?",
new String[] { staff.getNum() });
if (rs.next()) {
staff.setNum(rs.getString("num"));
staff.setName(rs.getString("name"));
staff.setSex(rs.getString("sex"));
staff.setSalary(rs.getString("salary"));
staff.setPhone(rs.getString("phone"));
staff.setDept(rs.getString("dept"));
staff.setDuty(rs.getString("duty"));
System.out.println("查到該資料" + staff.getNum());
} else {
System.out.println("沒有查到該資料");
return null;
}
} catch (SQLException e) {
e.printStackTrace();
return null;
} finally {
DBUtil.close();
}
return staff;
}
static public ResultSet checkSalary(Staff staff) {
ResultSet dutyRs = null;
try {
dutyRs = DBUtil.execQuery("select * from duty where name=?",
new String[] { staff.getDuty() });
} catch (SQLException e) {
e.printStackTrace();
}
return dutyRs;
}
static public ResultSet checkDept(Staff staff) {
ResultSet dutyRs = null;
try {
dutyRs = DBUtil.execQuery("select name from dept where name=?",
new String[] { staff.getDept() });
} catch (SQLException e) {
e.printStackTrace();
}
return dutyRs;
}
static public ResultSet checkDuty(Staff staff) {
ResultSet dutyRs = null;
try {
dutyRs = DBUtil.execQuery("select name from duty where name=?",
new String[] { staff.getDuty() });
} catch (SQLException e) {
e.printStackTrace();
}
return dutyRs;
}
}
Java+Springboot+H-ui+Maven實現行銷管理系統
Java+Springboot+Bootstrap+Maven實現網上商城系統
Java+Springboot+Bootstrap+Maven實現景區旅遊管理系統
1.更多JavaWeb系統請關注專欄。
2.更多JavaSwing系統請關注專欄。
注意員工編號為4位元數,職務和部門編號為3位數。管理員賬號和密碼都為admin。
請點選以下連結,部署你的專案。
如有侵權請聯絡我刪除。
如果您覺得此文對您有幫助,請點贊加關注加收藏。祝您生活愉快!