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

📄 docattributedao.java

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

/**
 * <p>Title: DocAttributeDAO</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 DocAttributeDAO {
	private int AttributeID;
	private String AttributeNO;
	private String AttributeName;
	private String ActiveTag;
	public DocAttributeDAO( int AttributeID, String AttributeNO, String AttributeName, String ActiveTag ){
		this.AttributeID = AttributeID;
		this.AttributeNO = AttributeNO;
		this.AttributeName = AttributeName;
		this.ActiveTag = ActiveTag;
	}
	public DocAttributeDAO() {
	}
	public int getAttributeID(){
		return AttributeID;
	}
	public void setAttributeID(int AttributeID){
		this.AttributeID = AttributeID;
	}
	public String getAttributeNO(){
		return AttributeNO;
	}
	public void setAttributeNO(String AttributeNO){
		this.AttributeNO = AttributeNO;
	}
	public String getAttributeName(){
		return AttributeName;
	}
	public void setAttributeName(String AttributeName){
		this.AttributeName = AttributeName;
	}
	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 DocAttributeDAO find(int AttributeID){
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocAttributeDAO result = null;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  AttributeID, AttributeNO, AttributeName, ActiveTag from TAttribute where AttributeID = ?");
			ps.setInt(1, AttributeID);
			rs = ps.executeQuery();
			if (rs.next()) {
				result = new DocAttributeDAO( 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 DocAttributeDAO[] findSelectAll() {
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocAttributeDAO result = null;
		Collection results = new ArrayList();
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  AttributeID, AttributeNO, AttributeName, ActiveTag from TAttribute");
			rs = ps.executeQuery();
			while (rs.next()) {
				result = new DocAttributeDAO( 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 (DocAttributeDAO[])results.toArray(new DocAttributeDAO[0]);
	}
	public static DocAttributeDAO[] findAll() {
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocAttributeDAO result = null;
		Collection results = new ArrayList();
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  AttributeID, AttributeNO, AttributeName, ActiveTag from TAttribute where ActiveTag = 1");
			rs = ps.executeQuery();
			while (rs.next()) {
				result = new DocAttributeDAO( 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 (DocAttributeDAO[])results.toArray(new DocAttributeDAO[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(AttributeID) from TAttribute");
				rs = ps.executeQuery();
				if (rs.next()){
					int maxAttributeID = rs.getInt(1)+1;
					this.setAttributeID(maxAttributeID);
				}
				ps = con.prepareStatement("insert into TAttribute ( AttributeID, AttributeNO, AttributeName, ActiveTag) values ( ?, ?, ?, ?)");
				ps.setInt(1, getAttributeID());
				ps.setString(2, getAttributeNO());
				ps.setString(3, getAttributeName());
				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 AttributeID) {
		Connection con = null;
		PreparedStatement ps = null;
		boolean blnReturn = false;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("delete TAttribute  where AttributeID = ?");
				ps.setInt(1, AttributeID);
				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 TAttribute set  AttributeID = ?, AttributeNO = ?, AttributeName = ?, ActiveTag = ? where AttributeID = ?");
				ps.setInt(1, getAttributeID());
				ps.setString(2, getAttributeNO());
				ps.setString(3, getAttributeName());
				ps.setString(4, getActiveTag());
				ps.setInt(5, getAttributeID());
				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) {
        DocAttributeDAO docAttributeDAO = new DocAttributeDAO();
        System.out.println(docAttributeDAO.findAll().length);
    }
}

⌨️ 快捷键说明

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