package pack_util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
import pack_mode.Deparment;
import pack_mode.Educate;
import pack_mode.Employee;
import pack_mode.Stipend;
/*数据库操作的公共类,包括验证数据的正确性,数据表的公共操作,添加,更新,删除*/
public class JdbcAdapter {
private Connection con;
PreparedStatement pstmt;
Statement statement=null;
String infoStr=null;
public void connecjdbc(){
try {
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/resources?user=root&password=111");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/*验证数据的正确性,通过主键判断数据表中是否存在这条数据*/
public boolean validateID(String tname,String idvalue){
String sql=null;
connecjdbc();
sql="select * from "+tname+" where ID= '"+idvalue+"'";
try {
pstmt = con.prepareStatement(sql);
ResultSet rs=null;
rs=pstmt.executeQuery();
if(rs.next()){
if(rs.getInt(1)>0)
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
//JOptionPane.showMessageDialog(null, "查找的信息不存在");
return false;
}
return false;
}
/*用来执行数据表中的所有操作*/
public boolean AdapterObjet(String sql){
connecjdbc();
try {
pstmt=con.prepareStatement(sql);
pstmt.execute();
JOptionPane.showMessageDialog(null, infoStr+"数据成功","系统提示",JOptionPane.INFORMATION_MESSAGE);
return true;
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
}
/*对员工数据表进行插入和修改操作*/
public boolean InsertOrUpdateEmployee(Employee employee){
String sql=null;
if(validateID("employee", employee.getID())){
sql="update employee set ID='"+employee.getID()+"',name='"+employee.getName()+"',sex='"+employee.getSex()+"'," +
"age='"+employee.getAge()+"',job='"+employee.getJob()+"',specialty='"+employee.getSpecialty()+"',experience='"+employee.getExperience()+"'," +
"studyeffort='"+employee.getStudyeffort()+"',school='"+employee.getSchool()+"',tel='"+employee.getTel()+"'," +
"email='"+employee.getEmail()+"',content='"+employee.getContent()+"' where ID='"+employee.getID()+"'";
infoStr="员工信息更新";
}
else{
sql="insert into employee values('"+employee.getID()+"','"+employee.getName()+"','"+employee.getSex()+"'," +
"'"+employee.getAge()+"','"+employee.getJob()+"','"+employee.getSpecialty()+"','"+employee.getExperience()+"'," +
"'"+employee.getStudyeffort()+"','"+employee.getSchool()+"','"+employee.getTel()+"','"+employee.getEmail()+"'," +
"'"+employee.getContent()+"')";
infoStr="员工信息添加";
}
return AdapterObjet(sql);
}
public boolean InsertOrUpdateInstitution(String ID,String name,String jiang,String fak,String content){
String sql=null;
if(validateID("Institution", ID)){
sql="update Institution set ID='"+ID+"',name='"+name+"'," +
"jiang='"+jiang+"',punishment='"+fak+"',content='"+content+"' where ID='"+ID+"'";
infoStr="奖惩信息修改";
}
else{
sql="insert into Institution values('"+ID+"','"+name+"','"+jiang+"','"+fak+"','"+content+"')";
infoStr="奖惩信息添加";
}
return AdapterObjet(sql);
}
/*对调度表的更新*/
public boolean UpdateReplace(String ID,String depname){
String sql=null;
if(validateID("employee", ID)){
sql="update employee set ID='"+ID+"',job='"+depname+"' where ID='"+ID+"'";
infoStr="员工职位调度";
return AdapterObjet(sql);
}
else return false;
}
/*对部门数据表的插入和修改*/
public boolean InsertOrUpdateDeparment(Deparment deparment){
String sql=null;
if(validateID("department", deparment.getID())){
sql="update department set ID='"+deparment.getID()+"',depname='"+deparment.getDepname()+"',chargeman='"+deparment.getChargeman()+"'," +
"Tel='"+deparment.getTel()+"',content='"+deparment.getContent()+"' where ID='"+deparment.getID()+"'";
infoStr="部门信息更新";
}
else{
sql="insert into department values('"+deparment.getID()+"','"+deparment.getDepname()+"'," +
"'"+deparment.getChargeman()+"','"+deparment.getTel()+"','"+deparment.getContent()+"')";
infoStr="部门信息添加";
}
return AdapterObjet(sql);
}
/*对培训数据表的插入和更新*/
public boolean InsertOrUpdateEducate(Educate educate){
String sql=null;
if(validateID("educate", educate.getID())){
sql="update educate set ID='"+educate.getID()+"',name='"+educate.getName()+"',purpose='"+educate.getPurpose()+"'," +
"begintime='"+educate.getBegintime()+"',student='"+educate.getStudent()+"',endtime='"+educate.getEndtime()+"',datum='"+educate.getDatum()+"'," +
"teacher='"+educate.getTeacher()+"',number='"+educate.getNumber()+"'," +
"effect='"+educate.getEffect()+"',summarize='"+educate.getSummarize()+"' where ID='"+educate.getID()+"'";
infoStr="培训信息更新";
}
else{
sql="insert into educate values('"+educate.getID()+"','"+educate.getName()+"','"+educate.getPurpose()+"','"+educate.getBegintime()+"'," +
"'"+educate.getStudent()+"','"+educate.getEndtime()+"','"+educate.getDatum()+"','"+educate.getTeacher()+"','"+educate.getNumber()+"'," +
"'"+educate.getEffect()+"','"+educate.getSummarize()+"')";
infoStr="培训信息添加";
}
return AdapterObjet(sql);
}
/*对工资数据表的插入和修改操作*/
public boolean InsertOrUpdateStipend(String[] string){
String sql=null;
sql="update stipend set send='"+string[2]+"',granttime='"+string[1]+"' where ID='"+string[0]+"'";
infoStr="工资发放";
/* else{
sql="insert into stipend values('"+stipend.getID()+"','"+stipend.getName()+"','"+stipend.getBasic()+"'," +
"'"+stipend.getEat()+"','"+stipend.getHouse()+"','"+stipend.getDuty()+"'," +
"'"+stipend.getJiaban()+"','"+stipend.getPunishment()+"','"+stipend.getOther()+"','"+stipend.getScot()+"','"+stipend.getSend()+"','"+stipend.getGranttime()+"')";
infoStr="工资信息添加";
}*/
return AdapterObjet(sql);
}
/*删除员工的信息,通过循环控制来生出批处理*/
public boolean deleteEmployee(Employee[] object){
connecjdbc();
try {
statement=con.createStatement();
for(int i=0;i<object.length;i++){
String sql="delete from employee where ID='"+object[i].getID()+"'";
statement.addBatch(sql);
}
statement.executeBatch();
JOptionPane.showMessageDialog(null, "员工信息数据删除成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/*删除单个员工的信心*/
public boolean deleteEmployeeone(String ID){
connecjdbc();
try {
statement=con.createStatement();
String sql="delete from employee where ID='"+ID+"'";
statement.addBatch(sql);
statement.executeBatch();
JOptionPane.showMessageDialog(null, "员工信息数据删除成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
return true;
}
/*删除部门信息*/
public boolean deleteDepartment(String ID){
connecjdbc();
try {
statement=con.createStatement();
String sql="delete from department where ID='"+ID+"'";
statement.addBatch(sql);
statement.executeBatch();
JOptionPane.showMessageDialog(null, "部门信息数据删除成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
} catch (SQLException e) {
// TOD
没有合适的资源?快使用搜索试试~ 我知道了~
人力资源管理系统(Java应用程序)
共95个文件
class:55个
java:35个
prefs:1个
需积分: 15 28 下载量 121 浏览量
2010-06-22
19:23:00
上传
评论 2
收藏 593KB RAR 举报
温馨提示
2010-5月做的课程设计,初学者可以一起商讨下 基本的需求都已经实现
资源推荐
资源详情
资源评论
收起资源包目录
课设.rar (95个子文件)
课设
.project 388B
bin
pack_mode
Deparment.class 1KB
Employee.class 3KB
Stipend.class 3KB
Check.class 1KB
Educate.class 3KB
pack_view
StipendSelect.class 5KB
replace$1.class 2KB
InstitutionSelect$1.class 2KB
StipendSelect$1.class 3KB
DepartmentUpdate$2.class 1KB
Employeeupdate$1.class 2KB
Departmentadd.class 2KB
DepartmentDel$1.class 2KB
EmployeeScan$1.class 2KB
InstitutionAdd.class 3KB
StipendSend.class 2KB
StipendSend$2.class 842B
Employeeupdate.class 4KB
DepartmentUpdate.class 3KB
EducateScan.class 4KB
InstitutionDel.class 1KB
InstitutionAdd$1.class 3KB
EmployeeScan.class 3KB
StipendSend$1.class 2KB
DepartmentUpdate$1.class 2KB
EmployeeSel.class 4KB
EmployeeSel$2.class 1KB
Employeeadd$1.class 2KB
SystemWindow.class 4KB
Departmentadd$1.class 1KB
Employeeupdate$2.class 2KB
SystemWindow$1.class 3KB
InstitutionSelect$2.class 2KB
StipendUpdate.class 1KB
EmployeeSel$1.class 3KB
DepartmentDel.class 3KB
Employeeadd.class 4KB
EducateScan$1.class 3KB
replace.class 3KB
InstitutionSelect.class 3KB
EducateAdd$1.class 2KB
EducateAdd.class 3KB
pack_test
Test_getObjectRow.class 1KB
Test.class 588B
Test_replace.class 592B
TestSql.class 3KB
Test_insertEmployee.class 992B
TestStipend.class 2KB
Test_InsertStipend.class 2KB
Test_validateID.class 828B
Test_InsertOrUpdata.class 1KB
Test_InterEducate.class 1KB
pack_util
JdbcAdapter.class 9KB
Commonjdbc.class 1KB
RetrieveObject.class 4KB
.settings
org.eclipse.jdt.core.prefs 629B
pic
3.jpg 30KB
src
pack_mode
Employee.java 2KB
Check.java 816B
Stipend.java 2KB
Deparment.java 992B
Educate.java 2KB
pack_view
DepartmentDel.java 2KB
InstitutionSelect.java 3KB
StipendSelect.java 6KB
InstitutionAdd.java 3KB
EmployeeSel.java 6KB
DepartmentUpdate.java 4KB
Employeeadd.java 4KB
EmployeeScan.java 2KB
SystemWindow.java 6KB
EducateScan.java 5KB
StipendSend.java 2KB
Departmentadd.java 2KB
EducateAdd.java 4KB
replace.java 3KB
InstitutionDel.java 956B
Employeeupdate.java 6KB
StipendUpdate.java 1KB
pack_test
Test_replace.java 1KB
TestStipend.java 1KB
Test_getObjectRow.java 517B
TestSql.java 2KB
Test_InsertOrUpdata.java 504B
Test.java 237B
Test_insertEmployee.java 596B
Test_validateID.java 278B
Test_InterEducate.java 656B
Test_InsertStipend.java 2KB
pack_util
Commonjdbc.java 678B
JdbcAdapter.java 9KB
RetrieveObject.java 3KB
.classpath 383B
DBDriver
mysql-connector-java-5.0.3-bin.jar 482KB
共 95 条
- 1
资源评论
wh070502219
- 粉丝: 15
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功