搜档网
当前位置:搜档网 › 简单的员工信息管理系统源码

简单的员工信息管理系统源码

简单的员工信息管理系统源码
简单的员工信息管理系统源码

据库连接3.查询4.增、5删6改(操作数据库)

import .*;

import .*;

import .*;

import .*;

public class EmpManageSys implements ActionListener { Connection con;

Statement stmt;

String sql;

ResultSet rs;

StringBuffer sb = new StringBuffer();

JTextField jtf2 = new JTextField("张飞",10);

JTextField jtf3 = new JTextField(10);

JTextField jtf4 = new JTextField(10);

JTextField jtf7 = new JTextField(10);

JTextField jtf5 = new JTextField(10);

JTextField jtf6 = new JTextField(10);

JTextField jtf8 = new JTextField(10);

JTextField jtf9 = new JTextField(10);

JTextArea jta10 = new JTextArea(50, 40);

public void actionPerformed(ActionEvent e) {

String str = ();

if ("查询".equals(str)) {

quals(str)) {

quals(str)) {

quals(str)) {

EmpManageSys() {

createGUI();

connectToDataBase();

public Connection connectToDataBase() { con = ();

(con);

return con;

}

public void searchEmp() {

("");

try {

stmt = ();

oLowerCase().trim() + "or id="

+ ().toLowerCase().trim() + "or engName=" + ().toLowerCase().trim() + "or UNIT="

+ ().toLowerCase().trim() + "or TEAM="

+ ().toLowerCase().trim() + "or Phone="

+ ().toLowerCase().trim() + "or region="

+ ().toLowerCase().trim() + "or busStation=" + ().toLowerCase().trim();

(sql);

rs = ();

ResultSetMetaData meta = ();

int cols = ();

while ()) {

for (int i = 1; i <= cols; i++) {

(" " + (i) + " =");

(i));

}

("\n");

());

}

} catch (SQLException e11) {

();

}

}

public void addEmp() {

try {

stmt = ();

sql = "update Mstar values(" + () + ()

+ () + () + ()

+ () + () + () + ")";

int i = ();

if (() != null) && () != null)

&& () != null) && () != null)) {

(sql);

("添加记录成功" + i + "条");

} else {

("带*号项为添加记录时不能为空");

}

} catch (SQLException e1) {

();

}

}

public void deleteEmp() {

searchEmp();

try {

stmt = ();

sql = "delete from Mstar where chineseName=" + ().toLowerCase().trim() + "or id="

+ ().toLowerCase().trim() + "or engName="

+ ().toLowerCase().trim() + "or UNIT="

+ ().toLowerCase().trim() + "or TEAM="

+ ().toLowerCase().trim() + "or Phone="

+ ().toLowerCase().trim() + "or region="

+ ().toLowerCase().trim() + "or busStation=" + ().toLowerCase().trim();

(sql);

int i = ();

("撤除操作成功" + i + "条");

} catch (SQLException e) {

();

}

}

public void alterEmp() {

searchEmp();

sql = "update Mstar set chineseName="

+ ().toLowerCase().trim() + "and id="

+ ().toLowerCase().trim() + "and engName=" + ().toLowerCase().trim() + "and UNIT="

+ ().toLowerCase().trim() + "and TEAM="

+ ().toLowerCase().trim() + "and Phone="

+ ().toLowerCase().trim() + "and region="

+ ().toLowerCase().trim() + "and busStation="

+ ().toLowerCase().trim();

int i = 0;

try {

(sql);

i = ();

} catch (SQLException e) {

();

}

("修改操作成功" + i + "条");

}

public void createGUI() {

JFrame jf = new JFrame("员工信息管理系统"); (new GridLayout(2, 1));

;

public class JdbcUtil

{

//load driver from file

static{

try{

String driverName =

"";

(driverName);

}catch(Exception e){

();

}

}

//establish connection

public static Connection getConnection(){

Connection con = null;

try{

String url =

"jdbc:oracle:thin

String usr = "openlab";

String pwd = "open123";

con = (

url,usr,pwd);

}catch(Exception e){

();

}

return con;

}

//close resultSet,statement and connection

public static void close(ResultSet rs,Statement stmt,Connection con){

try{

if(rs!=null) ();

}catch(Exception ex){ ();

}

try{

if(stmt!=null) ();

}catch(Exception ex){ ();

}

try{

if(con!=null) ();

}catch(Exception ex){ ();

}

}

}

相关主题