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

📄 docspecdatedao.java

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

/**
 * <p>Title: DocSpecDateDAO</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 DocSpecDateDAO {
	private String SpecDate;
	private String Time1;
	private String Time2;
	private String Time3;
	private String Time4;
	public DocSpecDateDAO( String SpecDate, String Time1, String Time2, String Time3, String Time4 ){
		this.SpecDate = SpecDate;
		this.Time1 = Time1;
		this.Time2 = Time2;
		this.Time3 = Time3;
		this.Time4 = Time4;
	}
	public DocSpecDateDAO() {
	}
	public String getSpecDate(){
		return SpecDate;
	}
	public void setSpecDate(String SpecDate){
		this.SpecDate = SpecDate;
	}
	public String getTime1(){
		return Time1;
	}
	public void setTime1(String Time1){
		this.Time1 = Time1;
	}
	public String getTime2(){
		return Time2;
	}
	public void setTime2(String Time2){
		this.Time2 = Time2;
	}
	public String getTime3(){
		return Time3;
	}
	public void setTime3(String Time3){
		this.Time3 = Time3;
	}
	public String getTime4(){
		return Time4;
	}
	public void setTime4(String Time4){
		this.Time4 = Time4;
	}

        //get the especiall days of a month
        //@year parameter
        //@month parameter
        public static DocSpecDateDAO[] findAll()
        {
               
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          ArrayList tmpList = new ArrayList();
          ExtendString ExStr = new ExtendString();
          try
          {
            DbConn dbConn = new DbConn();
            con = dbConn.getConnection();
           
            ps = con.prepareStatement("select SpecDate,Time1,Time2,Time3,Time4 from TSpecDate" );
            rs = ps.executeQuery();
            DocSpecDateDAO result = null;
            while(rs.next())
            {
              result = new DocSpecDateDAO( ExStr.dbDecode(rs.getString(1)), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)), ExStr.dbDecode(rs.getString(5)));
              tmpList.add(result);
              //System.out.println("-----3----");
            }
            rs.close();
            rs = null;
            ps.close();
            ps = null;
            con.close();
            con = null;
            return (DocSpecDateDAO[])tmpList.toArray(new DocSpecDateDAO[0]);
          }
          catch(Exception e)
          {
            System.out.println("error.don't get data from database" + e);
            return null;
          }
          finally
          {
            try
            {
              if(rs != null)
              {
                rs.close();
              }
            }
            catch(Exception e){}
            try
            {
              if(ps != null)
              {
                ps.close();
              }
            }
            catch(Exception e){}
            try
            {
              if(con != null)
              {
                con.close();
              }
            }
            catch(Exception e){}
          }
        }

        //to get a day that you want.
        public static DocSpecDateDAO findByDate(String date)
        {
          if(date == null )
          {
            System.out.println("Error!The parameter can't be null");
            return null;
          }
          Connection con = null;
          PreparedStatement ps = null;
          ResultSet rs = null;
          DocSpecDateDAO result = null;
          ExtendString ExStr = new ExtendString();
          try
          {
            DbConn dbConn = new DbConn();
            con = dbConn.getConnection();
            ps = con.prepareStatement("select SpecDate,Time1,Time2,Time3,Time4 from TSpecDate where SpecDate ='" + date + "'" );
            rs = ps.executeQuery();

            while(rs.next())
            {
              result = new DocSpecDateDAO( ExStr.dbDecode(rs.getString(1)), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)), ExStr.dbDecode(rs.getString(5)));
            }
            rs.close();
            rs = null;
            ps.close();
            ps = null;
            con.close();
            con = null;
            return result;
          }
          catch(Exception e)
          {
            System.out.println("error.don't get data from database" + e);
            return null;
          }
          finally
          {
            try
            {
              if(rs != null)
              {
                rs.close();
              }
            }
            catch(Exception e){}
            try
            {
              if(ps != null)
              {
                ps.close();
              }
            }
            catch(Exception e){}
            try
            {
              if(con != null)
              {
                con.close();
              }
            }
            catch(Exception e){}
          }
        }

        //to get a day that you want.
	public static DocSpecDateDAO findBySpecDate(String SpecDate){
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocSpecDateDAO result = null;

		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  SpecDate, Time1, Time2, Time3, Time4 from TSpecDate where SpecDate = ?");
			ps.setString(1, SpecDate);
			rs = ps.executeQuery();
			if (rs.next()) {
                result = new DocSpecDateDAO( ExStr.dbDecode(rs.getString(1)), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)), ExStr.dbDecode(rs.getString(5)));
                return 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 result;
	}
	/*
	public static DocSpecDateDAO[] findAll() {
		ExtendString ExStr = new ExtendString();
		Connection con = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		DocSpecDateDAO result = null;
		Collection results = new ArrayList();
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			ps = con.prepareStatement("select  SpecDate, Time1, Time2, Time3, Time4 from TSpecDate");
			rs = ps.executeQuery();
			while (rs.next()) {
				result = new DocSpecDateDAO( ExStr.dbDecode(rs.getString(1)), ExStr.dbDecode(rs.getString(2)), ExStr.dbDecode(rs.getString(3)), ExStr.dbDecode(rs.getString(4)), ExStr.dbDecode(rs.getString(5)));
				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 (DocSpecDateDAO[])results.toArray(new DocSpecDateDAO[0]);
	}
	*/
	public long insert() {
		Connection con = null;
		PreparedStatement ps = null;		
		
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("insert into TSpecDate ( SpecDate, Time1, Time2, Time3, Time4) values ( ?, ?, ?, ?, ?)");
				ps.setString(1, getSpecDate());
				ps.setString(2, getTime1());
				ps.setString(3, getTime2());
				ps.setString(4, getTime3());
				ps.setString(5, getTime4());				
				ps.executeUpdate();	
				
			}		
			ps.close();			
			ps = null;			
			con.close();			
			con = null;			
		}
		catch (SQLException e) {
			System.out.println("error" + e);
		}
		finally {			
			if (ps != null) {
				try {
					ps.close();
				}
				catch (SQLException sqlException) {
				}
				ps = null;
			}
			if (con != null) {
				try {
					con.close();
				}
				catch (SQLException sqlException) {
				}
				con = null;
			}
		}
		
		return 1;
	}

        //to delete the record that you want
        public boolean delete(String SpecDate) {
		Connection con = null;
		PreparedStatement ps = null;
		boolean blnReturn = false;
		try {
			DbConn dbConn = new DbConn();
			con = dbConn.getConnection();
			if (con != null) {
				ps = con.prepareStatement("delete TSpecDate  where SpecDate = ?");
				ps.setString(1, SpecDate);
				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;
	}

        //to update the special that you want.
	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 TSpecDate set  SpecDate = ?, Time1 = ?, Time2 = ?, Time3 = ?, Time4 = ? where SpecDate = ?");
				ps.setString(1, getSpecDate());
				ps.setString(2, getTime1());
				ps.setString(3, getTime2());
				ps.setString(4, getTime3());
				ps.setString(5, getTime4());
				ps.setString(6, getSpecDate());
				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)
        {
          DocSpecDateDAO da =  new DocSpecDateDAO("2003/08/02","dd","dd","dd","dd");
          //long l = da.insert();
          DocSpecDateDAO[] dd = DocSpecDateDAO.findAll();
          da = (DocSpecDateDAO)dd[0];
          System.out.println(da.getSpecDate()+da.getTime1());

        }
}

⌨️ 快捷键说明

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