⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personaldao.java~1~

📁 有完整的程序和源码
💻 JAVA~1~
字号:
//---------------------------------------------------------
// Application: Personal of System
// Author     : eSingle
// File       : PersonalDAO.java
//
// Copyright 2002 LandSoft Corp.
// Generated at Mon Nov 18 10:18:19 CST 2002
// Created by caoguangxin
// mailto:gxcao@mail.tsinghua.edu.cn
//---------------------------------------------------------

package com.landsoft.personal.dao;

import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;

import com.landsoft.personal.model.*;
import com.landsoft.personal.util.CacheManager;

public class PersonalDAO extends DAO {

  public PersonalDAO(DataSource ds) {
    super(ds);
  }

  public void insert(Personal personal) throws SQLException {
    String sql;
    sql = "INSERT INTO personal (personalid, name, sex, nationname, politics, diploma, businessname, typeofworkname, deptname, birthdate, folddate, joinworkdate, homeaddr, phone, mobile, email, identitycard, basepay) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = ds.getConnection();
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, personal.getPersonalid());
      pstmt.setString(2, personal.getName());
      pstmt.setString(3, personal.getSex());
      pstmt.setString(4, personal.getNationname());
      pstmt.setString(5, personal.getPolitics());
      pstmt.setString(6, personal.getDiploma());
      pstmt.setString(7, personal.getBusinessname());
      pstmt.setString(8, personal.getTypeofworkname());
      pstmt.setString(9, personal.getDeptname());
      pstmt.setDate(10, new java.sql.Date(personal.getBirthdate().getTime()));
      pstmt.setDate(11, new java.sql.Date(personal.getFolddate().getTime()));
      pstmt.setDate(12, new java.sql.Date(personal.getJoinworkdate().getTime()));
      pstmt.setString(13, personal.getHomeaddr());
      pstmt.setString(14, personal.getPhone());
      pstmt.setString(15, personal.getMobile());
      pstmt.setString(16, personal.getEmail());
      pstmt.setString(17, personal.getIdentitycard());
      pstmt.setString(18, personal.getBasepay());
      pstmt.executeUpdate();
      pstmt.close();
      conn.commit();
    } catch (SQLException sqle) {
      close(rs);
      close(pstmt);
      rollback(conn);
      sqle.printStackTrace();
      throw sqle;
    } finally {
    	close(conn);
    }
  }

  public void update(Personal personal) throws SQLException {
  	Connection conn = null;
  	PreparedStatement pstmt = null;
    try {
      conn = ds.getConnection();
      String sql = "UPDATE personal SET name=?, sex=?, nationname=?, politics=?, diploma=?, businessname=?, typeofworkname=?, deptname=?, birthdate=?, folddate=?, joinworkdate=?, homeaddr=?, phone=?, mobile=?, email=?, identitycard=?, basepay=? WHERE personalid=?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, personal.getName());
      pstmt.setString(2, personal.getSex());
      pstmt.setString(3, personal.getNationname());
      pstmt.setString(4, personal.getPolitics());
      pstmt.setString(5, personal.getDiploma());
      pstmt.setString(6, personal.getBusinessname());
      pstmt.setString(7, personal.getTypeofworkname());
      pstmt.setString(8, personal.getDeptname());
      pstmt.setDate(9, new java.sql.Date(personal.getBirthdate().getTime()));
      pstmt.setDate(10, new java.sql.Date(personal.getFolddate().getTime()));
      pstmt.setDate(11, new java.sql.Date(personal.getJoinworkdate().getTime()));
      pstmt.setString(12, personal.getHomeaddr());
      pstmt.setString(13, personal.getPhone());
      pstmt.setString(14, personal.getMobile());
      pstmt.setString(15, personal.getEmail());
      pstmt.setString(16, personal.getIdentitycard());
      pstmt.setString(17, personal.getBasepay());
      pstmt.setString(18, personal.getPersonalid());
      pstmt.executeUpdate();
      close(pstmt);
      conn.commit();
    } catch (SQLException e) {
      close(pstmt);
      rollback(conn);
      e.printStackTrace();
    } finally {
    	close(conn);
    }
  }

  public void delete(String personalid) throws SQLException {
  	Connection conn = null;
  	PreparedStatement pstmt = null;
    try {
      conn = ds.getConnection();
      String sql = "DELETE FROM personal WHERE personalid=?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, personalid);
      pstmt.executeUpdate();
      close(pstmt);
      conn.commit();
    } catch (SQLException e) {
      close(pstmt);
      rollback(conn);
      e.printStackTrace();
    } finally {
    	close(conn);
    }
    String[] objKeys = {"Personal", String.valueOf(personalid)};
    String objKey = CacheManager.createKey(objKeys);
    DAOCacheManager.invalidate(objKey);
  }

  public Personal retrieve(String personalid) throws SQLException {
    String[] objKeys = {"Personal", String.valueOf(personalid)};
    String objKey = CacheManager.createKey(objKeys);
    Personal personal = (Personal) DAOCacheManager.getCache(objKey);
    if (personal != null)
      return personal;
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = ds.getConnection();
      String sql = "SELECT * FROM personal WHERE personalid=?";
      pstmt = conn.prepareStatement(sql);
      pstmt.setString(1, personalid);
      rs = pstmt.executeQuery();
      if (rs.next()) {
        personal = new Personal();
        populate(personal, rs);
      }
      close(rs);
      close(pstmt);
    } catch (SQLException e) {
      close(rs);
      close(pstmt);
      rollback(conn);
      e.printStackTrace();
    } finally {
    	close(conn);
    }
    DAOCacheManager.putCache(personal, objKey, 1);
    return personal;
  }

  public List list() throws SQLException {
    String[] objKeys = {"Personal", "list"};
    String objKey = CacheManager.createKey(objKeys);
    ArrayList list = (ArrayList) DAOCacheManager.getCache(objKey);
    if (list != null)
      return list;
    list = new ArrayList();
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = ds.getConnection();
      String sql = "SELECT name, sex, nationname, politics, diploma, businessname, typeofworkname, deptname, birthdate, folddate, joinworkdate, homeaddr, phone, mobile, email, identitycard, basepay, personalid FROM personal";
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();
      while(rs.next()) {
        Personal personal = new Personal();
        populate(personal, rs);
        list.add(personal);
      }
      close(rs);
      close(pstmt);
    } catch (SQLException e) {
      close(rs);
      close(pstmt);
      rollback(conn);
      e.printStackTrace();
    } finally {
    	close(conn);
    }
    DAOCacheManager.putCache(list, objKey, 1);
    return list;
  }

  public List list(int offset, int limit) throws SQLException {
    String[] objKeys = {"Personal", "list", String.valueOf(offset), String.valueOf(limit)};
    String objKey = CacheManager.createKey(objKeys);
    ArrayList list = (ArrayList) DAOCacheManager.getCache(objKey);
    if (list != null)
      return list;
    list = new ArrayList();
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
      conn = ds.getConnection();
      String sql = "SELECT name, sex, nationname, politics, diploma, businessname, typeofworkname, deptname, birthdate, folddate, joinworkdate, homeaddr, phone, mobile, email, identitycard, basepay, personalid FROM personal";
      pstmt = conn.prepareStatement(sql);
      rs = pstmt.executeQuery();
      if(offset > 0) rs.absolute(offset);
      int recCount = 0;
      while((recCount++ < limit) && rs.next()) {
        Personal personal = new Personal();
        populate(personal, rs);
        list.add(personal);
      }
      close(rs);
      close(pstmt);
    } catch (SQLException e) {
      close(rs);
      close(pstmt);
      rollback(conn);
      e.printStackTrace();
    } finally {
    	close(conn);
    }
    DAOCacheManager.putCache(list, objKey, 1);
    return list;
  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -