《简单的员工信息管理系统源码.doc》由会员分享,可在线阅读,更多相关《简单的员工信息管理系统源码.doc(9页珍藏版)》请在三一文库上搜索。
1、据库连接 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);JT
2、extField 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) St
3、ring 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
4、().trim() + "or engName="+ ().toLowerCase().trim() + "or UNIT="+ ().toLowerCase().trim() + "or TEAM="+ ().toLowerCase().trim() + "or Phone="+ ().toLowerCase().trim() + "or busStation=" + ().toLowerCase().trim();(sql);rs = ();ResultSetMetaData meta =
5、();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 () != n
6、ull) && () != null)&& () != null) && () != null) (sql);("添加记录成功 " + i + " 条"); else ("带* 号项为添加记录时不能为空 "); catch (SQLException e1) ();public void deleteEmp() searchEmp();try stmt = ();sql = "delete from Mstar where chineseName="+ ().toLo
7、werCase().trim() + "or id="+ ().toLowerCase().trim() + "or UNIT="+ ().toLowerCase().trim() + "or engName="+ ().toLowerCase().trim() + "or TEAM=" + ().toLowerCase().trim() + "or Phone="+ ().toLowerCase().trim() + "or region="+ ().toLowerCase
8、().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().t
9、rim() + "and engName="+ ().toLowerCase().trim() + "and UNIT="+ ().toLowerCase().trim() + "and TEAM="+ ().toLowerCase().trim() + "and Phone="+ ().toLowerCase().trim() + "and region="+ ().toLowerCase().trim() + "and busStation="+ ().toLowerCa
10、se().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 statictryString driverName =(driverName);catch(Excepti
11、on e) ();/establish connectionpublic static Connection getConnection() Connection con = null;tryString url = "jdbc:oracle:thinString 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)();tryif(stmt!=null) ();catch(Exception ex)();tryif(con!=null) ();catch(Exception ex)();