医院检查人事管理数据库mysql_人事管理系统综合(连接mysql数据库,增删改查,通过解析导入XML文档)...

a4c26d1e5885305701be709a3d33442f.png

package com.aowin.stuff.dbconnection;

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;

public class Connections {

Connection con;

private String

url="jdbc:mysql://localhost:3306/test?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull";

String user="root";

private String password="12345";

static{

try {

Class.forName("com.mysql.jdbc.Driver");

System.out.println("加载驱动成功");

} catch (ClassNotFoundException

e) {

}

}

public Connection getConn(){

try {

con =

DriverManager.getConnection(url,user,password);

System.out.println("2133131");

} catch (SQLException e)

{

e.printStackTrace();

}

return con;

}

}

package com.aowin.stuff.dbconnection;

import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.SQLException;

import java.sql.Statement;

import com.aowin.stuff.model.Person;

import com.aowin.stuff.view.MainWindow;

import com.aowin.stuff.view.SubWindow;

public class Inserts {

Connections con=new Connections();

Connection conn=con.getConn();

public boolean insertAll(Person per){

try {

String

sql="insert into

person(id,name,sex,department,salary)values(?,?,?,?,?)"; PreparedStatement

stat = con.prepareStatement(sql);

stat.setInt(1,

per.getId());

stat.setString(2,

per.getName());

stat.setInt(3,

per.getSex());

stat.setString(4,

per.getDepartment());

stat.setInt(5,

per.getSalary());

// stat.executeUpdate();

stat.execute();

} catch (SQLException e)

{

e.printStackTrace();

}

return true;

}

}

package com.listener;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.UnsupportedEncodingException;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;

import java.util.Vector;

import javax.swing.JButton;

import javax.swing.JFileChooser;

import javax.swing.JMenuItem;

import javax.swing.JTable;

import org.dom4j.Document;

import org.dom4j.DocumentHelper;

import org.dom4j.Element;

import org.dom4j.io.SAXReader;

import org.dom4j.io.XMLWriter;

import org.xml.sax.XMLReader;

import com.model.Person;

import com.operation.Flush;

import com.operation.Inserts;

import com.view.MainWindow;

import com.view.SubWindow;

public class Mylistener extends MouseAdapter implements

ActionListener{

SubWindow sub;

Person per;

MainWindow m;

public Mylistener(SubWindow sub, MainWindow m)

{

this.sub=sub;

this.m=m;

}

@Override

public void actionPerformed(ActionEvent e)

{

String

str=e.getActionCommand();

System.out.println(str);

if(e.getSource() instanceof

JButton && "添加".equals(str)){

sub.getf().setVisible(true);

sub.getf().setTitle("添加"); }

if(e.getSource() instanceof

JButton && "更新".equals(str)){

Flush

flush=new Flush();

ArrayList

list=flush.flush();

for(int

i=0;i

m.model.addRow(list.get(i));

}

}

if(e.getSource() instanceof

JButton && "删除".equals(str)){

int[]

i=m.table.getSelectedRows();

for(int

j=i.length;j>0;j--){

m.model.removeRow(i[j-1]) ;

}

}

if(sub.getf().getTitle().equals("添加")&&

"清空".equals(str)){

sub.getFi().setText("");

sub.getFn().setText("");

sub.getFs().setToolTipText("");

sub.getFd().setText("");

sub.getFa().setText("");

}

if(sub.getf().getTitle().equals("添加")&&"确认".equals(str)){

per=new

Person();

per.setId(Integer.parseInt(sub.getFi().getText()));

per.setName(sub.getFn().getText());

if("男".equals(sub.getFs().getToolTipText())){

System.out.println(sub.getFs().getToolTipText());

per.setSex("男");

// }else

{

// per.setSex("女);

}

per.setDepartment(sub.getFd().getText());

per.setSalary(Integer.parseInt(sub.getFa().getText()));

Inserts

insert=new Inserts();

insert.insert(per);

}

if("导入".equals(str)){

JFileChooser

choose=new JFileChooser();

choose.showOpenDialog(m);

File file =

choose.getSelectedFile();

System.out.println("file="+file);

try {

SAXReader

r = new SAXReader();

Document

doc = r.read(file);

Element

root=doc.getRootElement();

List

list = root.elements();

Vector

v=new Vector();

for(int

i=0;i

Element

n=(Element)list.get(i);

Iterator

it=n.elementIterator();

while(it.hasNext()){

v.add(it.next().getText());

}

m.model.addRow(v);

}

} catch

(Exception e1) {

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值