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

📄 doccopydao.java

📁 一个简单的公文管理系统
💻 JAVA
字号:
package com.jasson.business.system;

/**
 * <p>Title: DocCopyDAO</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003,by wingroup</p>
 * <p>Company: wingroup</p>
 * @author jarrywen
 * @version 1.0
 */

import java.io.*;
import java.sql.*;
import java.util.Properties;
import java.util.Collection;
import java.util.ArrayList;
import com.jasson.business.common.DbConn;
import com.jasson.common.*;

public class DocCopyDAO {
	private int CopyID;
	private String CopyNO;
	private String CopyName;
	private String ActiveTag;

	public DocCopyDAO( int CopyID, String CopyNO, String CopyName, String ActiveTag ){
		this.CopyID = CopyID;
		this.CopyNO = CopyNO;
		this.CopyName = CopyName;
		this.ActiveTag = ActiveTag;
	}
	public DocCopyDAO() {
	}
	public int getCopyID(){
		return CopyID;
	}
	public void setCopyID(int CopyID){
		this.CopyID = CopyID;
	}
	public String getCopyNO(){
		return CopyNO;
	}
	public void setCopyNO(String CopyNO){
		this.CopyNO = CopyNO;
	}
	public String getCopyName(){
		return CopyName;
	}
	public void setCopyName(String CopyName){
		this.CopyName = CopyName;
	}
	public String getActiveTag(){
		return ActiveTag;
	}
	public void setActiveTag(String ActiveTag){
		this.ActiveTag = "0";
		if (ActiveTag != null) {
			if (ActiveTag.equals("1")) {
				this.ActiveTag = ActiveTag;
			}
		}
	}
	public static DocCopyDAO find(int CopyID){
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocCopyDAO result = null;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  CopyID, CopyNO, CopyName, ActiveTag from TCopy where CopyID = ?");
			ps.setInt(1, CopyID);
			rs = ps.executeQuery();
			if (rs.next()) {
				result = new DocCopyDAO( rs.getInt(1), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)));
			}
			rs.close();
			rs = null;
			ps.close();
			ps = null;
			con.close();
			con = null;
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (rs != null) {
				try {
					rs.close();
				}
				catch (SQLException sqlException) {
				}
				rs = null;
			}
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return result;
	}
	public static DocCopyDAO[] findSelectAll() {
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocCopyDAO result = null;
		Collection results = new ArrayList();
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  CopyID, CopyNO, CopyName, ActiveTag from TCopy");
			rs = ps.executeQuery();
			while (rs.next()) {
				result = new DocCopyDAO( rs.getInt(1), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)));
				results.add(result);
			}
			rs.close();
			rs = null;
			ps.close();
			ps = null;
			con.close();
			con = null;
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (rs != null) {
				try {
					rs.close();
				}
				catch (SQLException sqlException) {
				}
				rs = null;
			}
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return (DocCopyDAO[])results.toArray(new DocCopyDAO[0]);
	}	
	public static DocCopyDAO[] findAll() {
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocCopyDAO result = null;
		Collection results = new ArrayList();
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  CopyID, CopyNO, CopyName, ActiveTag from TCopy where ActiveTag = 1");
			rs = ps.executeQuery();
			while (rs.next()) {
				result = new DocCopyDAO( rs.getInt(1), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)));
				results.add(result);
			}
			rs.close();
			rs = null;
			ps.close();
			ps = null;
			con.close();
			con = null;
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (rs != null) {
				try {
					rs.close();
				}
				catch (SQLException sqlException) {
				}
				rs = null;
			}
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return (DocCopyDAO[])results.toArray(new DocCopyDAO[0]);
	}
	public long insert() {
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		long lngSQLReturn = -1;
		long lngReturn = -1;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("select MAX(CopyID) from TCopy");
				rs = ps.executeQuery();
				if (rs.next()){
					int maxCopyID = rs.getInt(1)+1;
					this.setCopyID(maxCopyID);
				}
				ps = con.prepareStatement("insert into TCopy ( CopyID, CopyNO, CopyName, ActiveTag) values ( ?, ?, ?, ?)");
				ps.setInt(1, getCopyID());
				ps.setString(2, getCopyNO());
				ps.setString(3, getCopyName());
				ps.setString(4, getActiveTag());
				lngSQLReturn = ps.executeUpdate();
				lngReturn = lngSQLReturn;
			}
			rs.close();
			rs = null;
			ps.close();
			ps = null;
			con.close();
			con = null;
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (rs != null) {
				try {
					rs.close();
				}
				catch (SQLException sqlException) {
				}
				rs = null;
			}
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return lngReturn;
	}
	public boolean delete(int CopyID) {
		Connection con = null;
		PreparedStatement ps = null;
		boolean blnReturn = false;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("delete TCopy  where CopyID = ?");
				ps.setInt(1, CopyID);
				blnReturn = (ps.executeUpdate() == 1);
				ps.close();
			}
			con.close();
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return blnReturn;
	}
	public boolean update() {
		Connection con = null;
		PreparedStatement ps = null;
		boolean blnReturn = false;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("update TCopy set  CopyID = ?, CopyNO = ?, CopyName = ?, ActiveTag = ? where CopyID = ?");
				ps.setInt(1, getCopyID());
				ps.setString(2, getCopyNO());
				ps.setString(3, getCopyName());
				ps.setString(4, getActiveTag());
				ps.setInt(5, getCopyID());
				blnReturn = (ps.executeUpdate() == 1);
				ps.close();
			}
			con.close();
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
		finally {
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		return blnReturn;
	}
    /**
     *
     */
    public static void main(String[] args) {
        DocCopyDAO docCopyDAO = new DocCopyDAO();
        ExtendCalendar ExCal = new ExtendCalendar();
        docCopyDAO.setActiveTag("1");
        docCopyDAO.setCopyID(2);
        docCopyDAO.setCopyName("1");
        docCopyDAO.setCopyNO("0011");
		Connection con = null;
		PreparedStatement ps = null;
		boolean blnReturn = false;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("update TCopy set  CopyID = ?, CopyNO = ?, CopyName = ?, ActiveTag = ?,CopyDate = ? where CopyID = ?");
				ps.setInt(1, docCopyDAO.getCopyID());
				ps.setString(2, docCopyDAO.getCopyNO());
				ps.setString(3, docCopyDAO.getCopyName());
				ps.setString(4, docCopyDAO.getActiveTag());
                //,ExCal.getCalendar()
                //new java.sql.Date(System.currentTimeMillis())
				//ps.setDate(5, new java.sql.Date(System.currentTimeMillis()),ExCal.getCalendar());
                //ps.setDate(5, new java.sql.Date(System.currentTimeMillis()));
                //ps.setDate(5, null);
                ps.setNull(5,java.sql.Types.DATE);
				ps.setInt(6, docCopyDAO.getCopyID());
				blnReturn = (ps.executeUpdate() == 1);
				ps.close();
			}
			con.close();
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}
        System.out.println(blnReturn);
        //java.sql.Date d1 = new java.sql.Date();
        //System.out.println(docCopyDAO.update());
		/*try {
		Connection con = null;
		Statement ps1 = null;
		ResultSet rs1 = null;
		Statement ps2 = null;
		ResultSet rs2 = null;
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps1 = con.createStatement();
			rs1 = ps1.executeQuery("select  CopyID, CopyNO, CopyName, ActiveTag from TCopy");
			while (rs1.next()) {
                System.out.println("*******");
                System.out.println("TCopy:"+rs1.getInt("CopyID"));
                System.out.println("*******");
                rs2 = ps1.executeQuery("select  KindID from TKind");
                while (rs2.next()) {
                System.out.println(rs2.getInt("KindID"));
                }
			}
			rs1.close();
			rs1 = null;
			ps1.close();
			ps1 = null;
			rs2.close();
			rs2 = null;
			ps2.close();
			ps2 = null;
			con.close();
			con = null;
		}
		catch (SQLException sqlException) {
			System.out.println(sqlException.getMessage());
		}*/
    }
}

⌨️ 快捷键说明

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