本文作者: 瓜西西

        本文主要面向openGauss数据库初学者,帮助初学者完成一些简单的数据库管理以及GUI,设计一个简单的人力资源管理系统。本文只包含部分代码,读者需要结合自己的数据库弹性公网、数据库用户及其密码等自身信息做出相应的修改。

一、实验环境

使用程序:putty.exe;

IntelliJ IDEA 2021.1.1;

apache-tomcat-9.0.46

服务器名称:ecs-d8b3

弹性公网:121.36.79.196

端口号:26000

表空间名:human_resource_space

数据库名称:human_resource

员工、部门经理登录账号:其员工ID

员工、部门经理登录密码:123456

人事经理登录账号:hr001

人事经理登录密码:hr001

登录入口(需在tomcat启动之后才能运行):http://localhost:8080/gaussdb2_war/login.jsp

二、创建和管理openGauss数据库

进行以下步骤前,需预先购买弹性云服务器 ECS ,并把需要的软件以及需要调用的包预先下载好。

2.1 数据库存储管理

2.1.1 连接弹性云服务器

我们使用 SSH 工具PuTTY,从本地电脑通过配置弹性云服务器的弹性公网 IP地址来连接 ECS,并使用 ROOT 用户来登录。

(1)点击putty.exe,打开putty


(2)输入弹性公网IP,点击open,连接弹性云服务器


2.1.2 启动、停止和连接数据库

2.1.1.1 启动数据库

(1)使用root登录


(2)切换至omm操作系统用户环境

使用语句切换至omm操作系统用户环境

su - omm 


(3)启动数据库

使用语句启动数据库

gs_om -t start 


2.1.1.2 停止数据库

如有需要,可以使用语句停止数据库

 gs_om -t stop 


2.1.1.3 连接数据库

使用 语句连接数据库。

gsql -d dbname -p port -U username -W password -r 


其中, -d 数据库名 -p 端口名 -U 用户名 -W 密码 -r 开启客户端操作历史记录功能


图中使用 gsql -d postgres -p 26000 -r 连接postgres数据库。postgres 为 openGauss 安装完成后默认生成的数据库,初始可以连接到此数据库进行新数据库的创建。26000 为数据库主节点的端口号。

2.1.3 创建和管理用户、表空间、数据库和模式

2.1.3.1 创建用户

使用以下语句创建用户。请牢记设置的用户名以及密码,之后需要多次使用。建议将密码都设置为相同的简单密码,方便之后的操作。

CREATE USER user_name PASSWORD pass_word


2.1.3.2 管理用户

可以使用以下语句对用户进行操作:

修改密码:

ALTER USER a IDENTIFIED BY 'Abcd@123' REPLACE ‘Guass@123'; 


删除用户:

DROP USER a CASCADE;


2.1.3.3 创建表空间

使用以下语句创建表空间。(路径需使用单引号)

 CREATE TABLESPACE human_resource_space RELATIVE LOCATION 'tablespace/tablespace_2'; 

创建表空间 human_resource_space,表空间路径为:tablespace/tablespace_2


2.1.3.4 管理表空间

(1)赋予用户表空间访问权限

使用以下语句,数据库系统管理员将human_resource_space表空间的访问权限赋予数据用户 a

 GRANT CREATE ON TABLESPACE human_resource_space TO a; 


(2)管理表空间

如有需要,可以使用如下语句 或 \db 语句查询表空间。

SELECT spcname FROM pg_tablespace;


可使用以下语句删除表空间

DROP TABLESPACE tablespace_1;


2.1.3.5 创建数据库

为用户a在表空间human_resource_space上创建数据库human_resource

 CREATE DATABASE human_resource WITH TABLESPACE = human_resource_space OWNER a; 


2.1.3.6 管理数据库

可以使用以下语句管理数据库:

SELECT datname FROM pg_database; 

或 \l 查看数据库

DROP DATABASE testdb;

删除数据库

2.1.3.7 创建模式

输入 \q 退出postgres数据库。


 gsql -d human_resource -p 26000 -U a -W aaa. -r


连接数据库human_resource。出现如下信息则连接成功:


使用语句

 CREATE SCHEMA a AUTHORIZATION a; 

 为用户创建同名模式a

2.1.3.8 管理模式

 SET SEARCH_PATH TO a,public; 

设置模式a为默认查询模式(设置中第一个为默认模式)

如有需要,可以使用语句 \dn 查看模式 ,SHOW SEARCH_PATH; 查看模式搜索路径

2.2 数据库对象管理实验

2.2.1 创建表

使用以下语句,在数据库human_resource_space,创建人力资源库的8个基本表。

CREATE TABLE table_name

( col1 datatype constraint,

col2 datatype constraint,

coln datatype constraint );


我们为了完成人力资源管理系统,创建雇佣历史表 employment_history 、部门表 sections、创建工作地点表 places、创建区域表 areas 、大学表 college、雇佣表 employments 、国家及地区表 states 、员工表 staffs这8个基本表。

以员工表为例:


2.2.2 删除表

如有需要,可以使用

DROP TABLE sections;

或 

 DROP TABLE sections CASCADE ;

语句删除表。

2.3 数据初始化

2.3.1 初始化数据表

我们这里方便操作,根据给定的txt文件初始化数据表,如果不嫌麻烦,也可以使用insert语句一条一条地插入。这两种方法本质上是一样的。

使用 

 INSERT INTO table_name \i /a.sql 

 语句初始化数据表(其中, a.sql是指定路径,执行给定的SQL脚本 )

使用 

SELECT * from table_name; 

 语句查看数据表信息。

以雇佣表 employments为例:



三、数据库应用程序开发

常见的数据库应用程序开发步骤为:

(1) 加载驱动

(2) 连接数据库

(3) 执行SQL语句

(4) 处理结果集

(5) 关闭连接

我们根据这5个步骤,实现人力资源管理系统。

3.1 项目框架


3.1.1 BLL

业务逻辑层,实现各项操作模块与servlet的接口,对传送数据进行逻辑判断分折,并进行传送正确的值。


3.1.2 Model

存放数据库表字段。在程序中,使用到的表有员工历史雇佣信息表、工作地点表、工作部门表、员工表。

这些java文件主要作用是定义各表的set和get函数


3.1.3 cn.UI

实现用户界面


3.1.4 Dao

实现具体的对数据库的操作,其中包含具体操作的函数以及SQL语句


3.1.4 Util

实现获得参数并传递参数以及连接数据库的功能


3.1.4 webapp

存放.jsp代码,生成具体页面。其中WEB-INF中存放web.xml文件


登录页面:


HRmanager页面:


manager页面:


staff页面:


6.2 修改表staffs

为了实现登录功能,我们需要在员工表staffs中增加一列password,为了方便起见,我们设置密码都为123456,当然也可以自己设置差异化的密码。

ALTER TABLE staffs ADD password varchar2(20);



UPDATE staffs SET password = 123456;



设置hr登录账号为hr001,密码为hr001

6.3 加载驱动&连接数据库

JDBC为JAVA中用来访问数据库的程序接口,我们使用JDBC连接。

文件路径为:


源码:

package Util;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Statement;

public class connect { //根据用户名与密码,进行数据库的连接以及关闭连接

private static String DBDriver="org.postgresql.Driver";

private static String url="jdbc:postgresql://121.36.79.196:26000/human_resource";

private static String user="a";

private static String password="aaa";

static Connection con=null;

static Statement sta=null;

static PreparedStatement pst =null;

//创建数据库的连接

public static Connection getConnection()

{

try {

Class.forName(DBDriver);

try {

con = DriverManager.getConnection(url, user, password);

return con;

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (ClassNotFoundException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

return null;

}

public static Statement createStatement()

{

try {

sta=getConnection().createStatement();

return sta;

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

//创造预处理对象

public static PreparedStatement createPreparedStatement(String sql)

{

try {

pst = getConnection().prepareStatement(sql);

return pst;

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return pst;

}

//关闭所有打开的资源

public static void closeOperation()

{

if(pst ==null)

{

try {

pst.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(sta==null)

{

try {

sta.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

if(con==null)

{

try {

con.close();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}


6.4 实现具体功能

文件路径:


完整源码:

package Dao;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.util.ArrayList;

import java.util.List;

import Model.*;

import Util.getInformation;

public class operate {

//********************************登录**************************************

//实现登录操作,登录成功返回true

public String login(String staff_id,String password){

if(staff_id.equals("hr001")){

if (password.equals("hr001")){

return staff_id;

}else {

return null;

}

}else {

String sql="select staff_id,password from staffs ";

ResultSet rs=Util.getInformation.executeQuery(sql);

try {

while(rs.next()){ //用户输入的账号密码和数据库中的信息做比较,判断输入是否正确;

Integer id = rs.getInt("staff_id");

String pwd = rs.getString("password");

if(id.equals(new Integer(staff_id)) && pwd.equals(password)){

return staff_id;

}

}

rs.close();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

return null;

}

//判断该员工是否为部门经理,返回部门编号

public String isManager(String staff_id){

String sql="select section_id,manager_id from sections";

ResultSet rs=Util.getInformation.executeQuery(sql);

try {

while(rs.next()){ //用户输入的账号密码和数据库中的信息做比较,判断输入是否正确;

Integer id = rs.getInt("manager_id");

String section_id = rs.getString("section_id");

if(id.equals(new Integer(staff_id))){

return section_id;

}

}

rs.close();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return "null";

}

//**********************************员工操作***********************************

//修改电话号码

public void updatePhoneNumber(String phone_number,String staff_id){

String sql = "update staffs set phone_number=? where staff_id=? ";

Util.getInformation.executeUpdate(sql, phone_number, new Integer(staff_id));

}

//**********************************部门经理**********************************

//查询部门所有员工信息(按员工编号升序排列)

public List QuerySectionStaffsOrderByStaffId(Integer section_id)

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from staffs where section_id=? order by staff_id asc";

ResultSet rs=getInformation.executeQuery(sql,section_id);

try {

while(rs.next())

{

//保存取出来的每一条记录

staffs staff =new staffs();

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

list.add(staff);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//查询部门所有员工信息(按工资降序排列)

public List QuerySectionStaffsOrderBySalary(Integer section_id)

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from staffs where section_id=? order by salary desc";

ResultSet rs=getInformation.executeQuery(sql,section_id);

try {

while(rs.next())

{

//保存取出来的每一条记录

staffs staff =new staffs();

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

list.add(staff);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//根据员工号查询部门内员工,然后返回该员工信息

public staffs QuerySectionStaffByStaff_id(Integer staff_id,Integer section_id)

{

staffs staff =new staffs();

String sql="select * from staffs where staff_id=? and section_id=?";

ResultSet rs=getInformation.executeQuery(sql, staff_id,section_id);

try {

if(rs.next())

{

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

}

} catch (NumberFormatException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return staff;

}

//根据员工姓名查询部门内员工,然后返回该员工信息

public staffs QuerySectionStaffByFirstName(String first_name,Integer section_id)

{

staffs staff =new staffs();

String sql="select * from staffs where first_name=? and section_id=?";

ResultSet rs=getInformation.executeQuery(sql, first_name,section_id);

try {

if(rs.next())

{

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

}

} catch (NumberFormatException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return staff;

}

public List SectionStatistics(String section_id)

{

ArrayList list =new ArrayList(); // 初始化

String sql="select avg(salary),min(salary),max(salary) from staffs where section_id = ?;";

ResultSet rs=getInformation.executeQuery(sql,section_id);

try {

while(rs.next())

{

//保存取出来的每一条记录

list.add(rs.getInt("avg"));

list.add(rs.getInt("max"));

list.add(rs.getInt("min"));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//******************************人事经理操作*****************************************

//根据员工号查询员工,然后返回该员工信息

public staffs QueryStaffByStaff_id(Integer staff_id)

{

staffs staff =new staffs();

String sql="select * from staffs where staff_id=?";

ResultSet rs=getInformation.executeQuery(sql, staff_id);

try {

if(rs.next())

{

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

}

} catch (NumberFormatException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return staff;

}

//根据员工姓名查询员工,然后返回该员工信息

public staffs QueryStaffByFirstName(String first_name)

{

staffs staff =new staffs();

String sql="select * from staffs where first_name=?";

ResultSet rs=getInformation.executeQuery(sql, first_name);

try {

if(rs.next())

{

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

}

} catch (NumberFormatException | SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return staff;

}

//查询所有员工信息(按员工编号升序排列)

public List QueryAllStaffsOrderByStaffId()

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from staffs order by staff_id asc";

ResultSet rs=getInformation.executeQuery(sql);

try {

while(rs.next())

{

//保存取出来的每一条记录

staffs staff =new staffs();

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

list.add(staff);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//查询所有员工信息(按工资降序排列)

public List QueryAllStaffsOrderBySalary()

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from staffs order by salary desc";

ResultSet rs=getInformation.executeQuery(sql);

try {

while(rs.next())

{

//保存取出来的每一条记录

staffs staff =new staffs();

staff.setStaff_id(rs.getInt("staff_id"));

staff.setFirst_name(rs.getString("first_name"));

staff.setLast_name(rs.getString("last_name"));

staff.setEmail(rs.getString("email"));

staff.setPhone_number(rs.getString("phone_number"));

staff.setHire_date(rs.getDate("hire_date"));

staff.setEmployment_id(rs.getString("employment_id"));

staff.setSalary(rs.getInt("salary"));

staff.setCommission_pct(rs.getInt("commission_pct"));

staff.setManager_id(rs.getInt("manager_id"));

staff.setSection_id(rs.getInt("section_id"));

staff.setGraduated_name(rs.getString("graduated_name"));

staff.setPassword(rs.getString("password"));

list.add(staff);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

public List statistics( )

{

ArrayList list =new ArrayList(); // 初始化

String sql="select avg(salary),min(salary),max(salary),section_id from staffs group by section_id;";

ResultSet rs=getInformation.executeQuery(sql);

try {

while(rs.next())

{

//保存取出来的每一条记录

list.add(rs.getInt("section_id"));

list.add(rs.getInt("avg"));

list.add(rs.getInt("max"));

list.add(rs.getInt("min"));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//查询所有部门信息

public List QuerySectionOrderBySectionId()

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from sections order by section_id asc";

ResultSet rs=getInformation.executeQuery(sql);

try {

while(rs.next())

{

//保存取出来的每一条记录

sections sections =new sections();

sections.setSection_id(rs.getInt("section_id"));

sections.setSection_name(rs.getString("section_name"));

sections.setManager_id(rs.getInt("manager_id"));

sections.setPlace_id(rs.getInt("place_id"));

list.add(sections);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//查询所有工作地点信息

public List QueryPlaces()

{

List list=new ArrayList(); //最终返回整个list集合

String sql="select * from places";

ResultSet rs=getInformation.executeQuery(sql);

try {

while(rs.next())

{

//保存取出来的每一条记录

places places = new places();

places.setPlace_id(rs.getInt("place_id"));

places.setStreet_address(rs.getString("street_address"));

places.setPostal_code(rs.getString("postal_code"));

places.setCity(rs.getString("city"));

places.setState_province(rs.getString("state_province"));

places.setState_id(rs.getString("state_id"));

list.add(places);

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

//修改部门名称

public void updateSectionName(String section_name,Integer section_id){

String sql = "update sections set section_name=? where section_id=? ";

Util.getInformation.executeUpdate(sql, section_name, section_id);

}

//实现添加新工作地点

public void addPlace(places place)

{

String sql="insert into places (place_id, street_address, postal_code, city, state_province,state_id) values (?,?,?,?,?,?)";

Util.getInformation.executeUpdate(sql, place.getPlace_id(),place.getStreet_address(), place.getPostal_code(), place.getCity(), place.getState_province(), place.getState_id());

}

// 查询员工工作信息

public List QueryStaffEmployment(String staff_id)

{

List list=new ArrayList(); //最终返回整个list集合

String sql="SELECT staff_id,employment_id,section_id\n" +

"FROM staffs\n" +

"WHERE staff_id = ?\n" +

"\n" +

"UNION\n" +

"\n" +

"SELECT staff_id,employment_id,section_id\n" +

"FROM employment_history\n" +

"WHERE staff_id = ?;";

Integer id = new Integer(staff_id);

ResultSet rs=getInformation.executeQuery(sql,id,id);

try {

while(rs.next())

{

//保存取出来的每一条记录

list.add(rs.getString("staff_id"));

list.add(rs.getString("employment_id"));

list.add(rs.getString("section_id"));

}

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return list;

}

}


四、结果展示

运行login.jsp进入登录界面

4.1 以员工身份登录

1)输入staff_id 和 正确的密码,进入员工主页面;

输入staff_id=104,密码123456,进入员工页面


2)在员工主页面,可以选择查看员工自己基本信息;


3)在员工主页面,修改员工自己的电话号码;

选择修改电话号码,填入590.423.4567


可以重新查询,电话号码改变


4.2 以部门经理身份登录

1)输入staff_id 和 正确的密码,进入部门经理主页面;

输入staff_id=103,密码123456,进入经理页面


2)在部门经理主页面,可以查看本部门所有员工基本信息(选择按员工编号升序排列,或者按工资降序排列);

查看本部门所有员工基本信息:

按员工编号升序排列:


按工资降序排列:


3)在部门经理主页面,可以按员工编号查询员工基本信息;



4)在部门经理主页面,可以按员工姓名查询员工基本信息;



5)在部门经理主页面,可以统计查询本部门员工最高工资,最低工资以及平均工资;


4.3 以人事经理身份登录

1)输入特定编号hr001 和 特定密码,进入人事经理主页面;

输入staff_id=hr001,密码hr001,进人事经理主页面


2)在人事经理主页面,可以查看所有员工基本信息(选择按员工编号升序排列,或者按工资降序排列);

按员工编号升序排列:


按工资降序排列:


3)在人事经理主页面,可以按员工编号查询员工基本信息;



4)在人事经理主页面,可以按员工姓名查询员工基本信息;



5)在人事经理主页面,可以统计各部门员工最高工资,最低工资以及平均工资;


6)在人事经理主页面,可以查询各部门基本信息,并可以根据部门编号修改部门名称;


修改名称:




7)在人事经理主页面,可以各工作地点基本信息,并可以增加新的工作地点;




8)在人事经理主页面,可以按员工编号查询员工工作信息,包括其历史工作信息,返回员工编号,职位编号和部门编号;



五、可能遇到的问题

5.1 Java开发工具不同:IntelliJ IDEA V.S. Eclipse

笔者一开始使用过Eclipse,但是在后期转而使用IntelliJ IDEA,这是因为Eclipse有一些缺陷,比如报错不明显,这对于初学者而言很可能是致命的。IntelliJ IDEA的优势之一是能在右侧Database处直接连接openGauss数据库(需选择PostgreSQL数据库)。而需要注意IntelliJ IDEA只能免费试用一个月。


5.2 连接openGauss数据库报错

第一步连接数据库时,Eclipse出现以下报错,但是它并没有指明究竟是哪里出错。一般出现如下错误,是因为连接openGauss数据库失败,原因可能为以下几点:


(1)url使用错误

这里121.36.79.196为弹性公网ip,26000为端口号,human_resource为数据库名称。如果url错误,则会导致数据库无法连接。

url="jdbc:postgresql://121.36.79.196:26000/human_resource";

(2)数据库用户或者密码错误

数据库用户或密码错误也会导致连接出错。所以必须牢记用户名及密码,否则容易使用错误。

private static String user="a";

private static String password="aaa";


(3)java版本错误

openGauss适用于java的版本为1.8,其他版本可能会报错。

(4)调包出错

连接数据库需要调用postgresql.jar包,建议提前配置jar包到项目中。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐