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

📄 docsecretdao.java

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

/**
 * <p>Title: DocSecretDAO</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 DocSecretDAO {
    private int SecretID;
    private String SecretNO;
    private String SecretName;
    private String ActiveTag;
    public DocSecretDAO( int SecretID, String SecretNO, String SecretName, String ActiveTag ){
        this.SecretID = SecretID;
        this.SecretNO = SecretNO;
        this.SecretName = SecretName;
        this.ActiveTag = ActiveTag;
    }
    public DocSecretDAO() {
    }
    public int getSecretID(){
        return SecretID;
    }
    public void setSecretID(int SecretID){
        this.SecretID = SecretID;
    }
    public String getSecretNO(){
        return SecretNO;
    }
    public void setSecretNO(String SecretNO){
        this.SecretNO = SecretNO;
    }
    public String getSecretName(){
        return SecretName;
    }
    public void setSecretName(String SecretName){
        this.SecretName = SecretName;
    }
    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 DocSecretDAO find(int SecretID){
        ExtendString ExStr = new ExtendString();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        DocSecretDAO result = null;
        try {
            DbConn dbConn = new DbConn();
            con = dbConn.getConnection();
            ps = con.prepareStatement("select  SecretID, SecretNO, SecretName, ActiveTag from TSecret where SecretID = ?");
            ps.setInt(1, SecretID);
            rs = ps.executeQuery();
            if (rs.next()) {
                result = new DocSecretDAO( 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 DocSecretDAO[] findAll() {
        ExtendString ExStr = new ExtendString();
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        DocSecretDAO result = null;
        Collection results = new ArrayList();
        try {
            DbConn dbConn = new DbConn();
            con = dbConn.getConnection();
            ps = con.prepareStatement("select  SecretID, SecretNO, SecretName, ActiveTag from TSecret where ActiveTag = 1");
            rs = ps.executeQuery();
            while (rs.next()) {
                result = new DocSecretDAO( 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 (DocSecretDAO[])results.toArray(new DocSecretDAO[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(SecretID) from TSecret");
                rs = ps.executeQuery();
                if (rs.next()){
                    int maxSecretID = rs.getInt(1)+1;
                    this.setSecretID(maxSecretID);
                }
                ps = con.prepareStatement("insert into TSecret ( SecretID, SecretNO, SecretName, ActiveTag) values ( ?, ?, ?, ?)");
                ps.setInt(1, getSecretID());
                ps.setString(2, getSecretNO());
                ps.setString(3, getSecretName());
                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 SecretID) {
        Connection con = null;
        PreparedStatement ps = null;
        boolean blnReturn = false;
        try {
            DbConn dbConn = new DbConn();
            con = dbConn.getConnection();
            if (con != null) {
                ps = con.prepareStatement("delete TSecret  where SecretID = ?");
                ps.setInt(1, SecretID);
                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 TSecret set  SecretID = ?, SecretNO = ?, SecretName = ?, ActiveTag = ? where SecretID = ?");
                ps.setInt(1, getSecretID());
                ps.setString(2, getSecretNO());
                ps.setString(3, getSecretName());
                ps.setString(4, getActiveTag());
                ps.setInt(5, getSecretID());
                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;
    }
}

⌨️ 快捷键说明

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