人事管理系统Word文档下载推荐.docx
- 文档编号:19479032
- 上传时间:2023-01-06
- 格式:DOCX
- 页数:63
- 大小:34.81KB
人事管理系统Word文档下载推荐.docx
《人事管理系统Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《人事管理系统Word文档下载推荐.docx(63页珍藏版)》请在冰豆网上搜索。
//localhost:
3306/manage"
;
//数据库地址
Stringuser="
root"
//用户
Stringpassword="
123"
//密码
publicbooleanflag=true;
//1加载驱动
publicvoidconnection(){
try{
Class.forName("
com.mysql.jdbc.Driver"
);
//加载驱动,驱动程序类自身的一个static代码块自动生成驱动程序的实例
//System.out.println("
加载成功"
}catch(ClassNotFoundExceptione1){
System.out.println("
加载失败"
}
try{//获得连接
DriverManager.getConnection(url,user,password);
//connection类型连接数据库
连接成功"
}catch(SQLExceptione111){
连接失败"
//2查询全部并导入数据
publicvoidlead(){
connection();
Stringsql="
select*fromcompany"
ste1=DriverManager.getConnection(url,user,password).createStatement();
//connection类下的Statement对象执行SQL
rt1=ste1.executeQuery(sql);
//ResultSet结果集合
}catch(SQLExceptione1){
e1.printStackTrace();
//3并添加数据
publicvoidadd(intId,StringName,intSex,StringDapartment,intSalary){
connection();
Stringsql="
insertintocompanyvalues(?
?
)"
try{
ps1=DriverManager.getConnection(url,user,password).prepareStatement(sql);
//定义一个?
号的内容
ps1.setInt(1,Id);
ps1.setString(2,Name);
//插入第一个?
号
ps1.setInt(3,Sex);
ps1.setString(4,Dapartment);
ps1.setInt(5,Salary);
ps1.execute();
//执行
System.out.println("
添加成功"
}catch(SQLExceptione){
flag=false;
JOptionPane.showMessageDialog(null,"
已经有此编号了"
"
消息框"
0);
}
}
//4删除数据
publicbooleandelete(intId){
deletefromcompanywhereId=?
"
try{
ps2=DriverManager.getConnection(url,user,password).prepareStatement(sql);
ps2.setInt(1,Id);
ps2.execute();
System.out.println("
删除成功"
}catch(SQLExceptione){
操作失败"
returnfalse;
returntrue;
//5修改数据
publicBooleanupdate(intId,StringName,intSex,StringDapartment,intSalary){
updatecompanysetName=?
Sex=?
Dapartment=?
Salary=?
whereId=?
//问号不能有有引号
ps3=DriverManager.getConnection(url,user,password).prepareStatement(sql);
ps3.setString(1,Name);
ps3.setInt(2,Sex);
ps3.setString(3,Dapartment);
ps3.setInt(4,Salary);
ps3.setInt(5,Id);
ps3.execute();
修改成功"
//按各个查询
//按Id查询
publicArrayList<
Person>
selectId(intId){//
ArrayList<
arr=newArrayList<
();
System.out.println(Id);
select*fromcompanywhereId=?
"
ps4=DriverManager.getConnection(url,user,password).prepareStatement(sql);
ps4.setInt(1,Id);
ps4.execute();
rt2=ps4.executeQuery();
while(rt2.next()){
arr.add(newPerson(rt2.getInt
(1),rt2.getString
(2),rt2.getInt(3),rt2.getString(4),rt2.getInt(5)));
System.out.println("
查询成功"
}catch(SQLExceptione){
}
returnarr;
//按Name查询
selectName(StringName){
select*fromcompanywhereNamelike?
ps4.setString(1,"
%"
+Name+"
//按Sex查询
selectSex(intSex){
select*fromcompanywhereSex=?
ps4.setInt(1,Sex);
//按Dapartment查询
selectDapartment(StringDapartment){
select*fromcompanywhereDapartment=?
ps4.setString(1,Dapartment);
//按Salary查询
selectSalary(intSalary){
select*fromcompanywhereSalary=?
ps4.setInt(1,Salary);
//更新时添加
publicvoidadd2(intId,StringName,intSex,StringDapartment,intSalary){
connection();
StringSex2=null;
Stringsql="
try{
ps1=DriverManager.getConnection(url,user,password).prepareStatement(sql);
ps1.setInt(1,Id);
ps1.setString(2,Name);
ps1.setInt(3,Sex);
ps1.setString(4,Dapartment);
ps1.setInt(5,Salary);
if(String.valueOf(Sex).equals("
1"
)){
Sex2="
男"
}elseif(String.valueOf(Sex).equals("
0"
女"
ps1.execute();
System.out.println(Id+"
+Name+"
+Sex2+"
+Dapartment+"
+Salary+"
}catch(SQLExceptione){
System.out.println("
已经有Id:
+Id+"
该条"
数据添加失败"
//e.printStackTrace();
}
publicStatementgetSte1(){
returnste1;
publicResultSetgetRt1(){
returnrt1;
}
Lisnter包
packagecom.lisnter;
importjava.awt.event.ActionEvent;
importjava.awt.event.ActionListener;
importjavax.swing.JComboBox;
importjavax.swing.JTextField;
importcom.jdbc.Jdbc;
importcom.swing.Model;
importcom.swing.Model2;
*AddListening类——主要用于添加表格数据的类,实现表格和数据库交互,与数据库同步
publicclassAddListeningimplementsActionListener{
Model2M2;
ModelM1;
publicAddListening(Model2M2){
this.M2=M2;
publicAddListening(ModelM1,Model2M2){
this.M1=M1;
intId;
StringName;
intSex;
StringDapartment;
intSalary;
@Override
publicvoidactionPerformed(ActionEvente){
Stringstr=e.getActionCommand();
if(str.equals("
确定"
//拿到各个器件
JTextFieldf1=M2.getField1();
JTextFieldf2=M2.getField2();
JComboBoxc3=M2.getCbox3();
JComboBoxc4=M2.getCbox4();
JTextFieldf5=M2.getField5();
//得到文本的值
Stringr11=f1.getText();
Stringr22=f2.getText();
Stringr33=(String)c3.getSelectedItem();
Stringr44=(String)c4.getSelectedItem();
Stringr55=f5.getText();
//提示输入有误
booleanflag=true;
Stringregex="
\\d+"
//数字字符串
booleanflag1=r11.matches(regex);
//匹配数字
booleanflag2=r55.matches(regex);
if(r11.equals("
编号输入不能有空"
}elseif(!
flag1){
编号输入必须全为数字"
}elseif(r22.equals("
姓名输入不能有空"
}elseif(r55.equals("
工资输入不能有空"
flag2){
工资输入必须全为数字"
}else{
//写入数据库中
Id=Integer.valueOf(f1.getText());
Name=f2.getText();
Sex=c3.getSelectedIndex();
Dapartment=(String)c4.getSelectedItem();
Salary=Integer.valueOf(f5.getText());
Jdbcj=newJdbc();
j.add(Id,Name,Sex,Dapartment,Salary);
//jdbc中的添加方法
flag=j.flag;
}
if(flag){
String[]s1={r11,r22,r33,r44,r55};
M1.getModel().addRow(s1);
M2.getFrame().setVisible(false);
//关闭
取消"
importjava.io.File;
importjavax.swing.JFileChooser;
importjavax.swing.table.DefaultTableModel;
importjavax.xml.parsers.ParserConfigurationException;
importjavax.xml.transform.TransformerException;
importcom.Xml.Dom;
importcom.swing.SelectModle;
*主界面监听类——用于主界面各
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 人事管理系统
![提示](https://static.bdocx.com/images/bang_tan.gif)