EmployeeInfoBean.java~37~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package humanresource;
- import java.sql.*;
- import java.util.*;
- public class EmployeeInfoBean {
- private String name, address, phone;
- private int id;
- private static Connection conn;
- private Statement statement;
- ResultSet rs;
- public void setName(String input){
- name = input;
- }
- public String getName(){
- return name;
- }
- public void setAddress(String input){
- address = input;
- }
- public String getAddress(){
- return address;
- }
- public void setPhone(String input){
- phone = input;
- }
- public String getPhone(){
- return phone;
- }
- public void setId(int input){
- id = input;
- }
- public int getId(){
- return id;
- }
- public static Connection coninit(){
- ParserXml myParser = new ParserXml("config.xml");
- Properties props = myParser.getProps();
- String dbDriver = props.getProperty("driver");
- String dbUrl = props.getProperty("url");
- System.out.println(dbUrl);
- try {
- Class.forName(dbDriver);
- conn= DriverManager.getConnection(dbUrl);
- }
- catch (SQLException ex) {
- }
- catch (ClassNotFoundException ex) {
- }
- return conn;
- }
- public void updateDatabase(){
- try{
- Connection con1=EmployeeInfoBean.coninit();
- String sql = "UPDATE EMPLOYEEINFO SET " +
- "NAME=?, ADDRESS=?, PHONE=? WHERE ID=?";
- PreparedStatement statement = conn.prepareStatement(sql);
- statement.setString(1, name);
- statement.setString(2, address);
- statement.setString(3, phone);
- statement.setInt(4, id);
- statement.executeUpdate();
- }
- catch (Exception e) {}
- }
- public ResultSet queryComPolicy(){
- try {
- Connection con1=EmployeeInfoBean.coninit();
- statement = con1.createStatement();
- String sql = "SELECT * FROM BENEFITINFO";
- rs = statement.executeQuery(sql);
- }
- catch (SQLException ex) {
- }
- return rs;
- }
- public ResultSet queryPenPolicy(int employeeID){
- try {
- Connection con1=EmployeeInfoBean.coninit();
- String sql = "SELECT * FROM EMPLOYEEINFO WHERE ID = ?";
- PreparedStatement statement = conn.prepareStatement(sql);
- statement.setInt(1,1);
- rs = statement.executeQuery();
- // System.out.println(statement);
- //System.out.println("结果集有问题");
- }
- catch (SQLException ex) {
- }
- return rs;
- }
- }