EmployeeInfoBean.java~32~
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package humanresource;
- import java.sql.*;
- 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(){
- try {
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
- conn= DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=HumanResourcesDB;User=sa;Password=sa");
- }
- 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.executeQuery();
- }
- 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);
- System.out.println("结果集有问题");
- rs = statement.executeQuery(sql);
- // System.out.println(statement);
- //System.out.println("结果集有问题");
- }
- catch (SQLException ex) {
- }
- return rs;
- }
- }