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

📄 dao.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
字号:
package com.ebusiness.ebank.dao;/** * <p>Title: </p> * <p>Description: This is an abstract super class to access data. All of the concrete *                  DAO classes needs to extends this super class.</p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author unascribed * @version 1.0 */import java.sql.Connection;import java.sql.PreparedStatement;import java.sql.Statement;import java.sql.ResultSet;import java.sql.SQLException;import javax.sql.DataSource;import org.apache.log4j.Logger;import org.apache.log4j.MDC;import com.ebusiness.ebank.servicedelegate.ServiceLocator;import com.ebusiness.ebank.servicedelegate.ServiceLocatorException;import com.ebusiness.ebank.exception.SystemException;import com.ebusiness.ebank.exception.ErrorMessages;import com.ebusiness.ebank.security.UserProfile;import com.ebusiness.ebank.util.Constants;public class DAO{    protected Connection con;    protected PreparedStatement ps;    protected ResultSet rs;    protected UserProfile profile;    private static DataSource ds;    private Logger log = Logger.getLogger(this.getClass());    //Set connection to this DAO object    protected void setConnection() throws SystemException    {        try        {            if (ds == null)                ds = ServiceLocator.getInstance().getDataSource(Constants.DATASOURCE_EBANK);            con = ds.getConnection();        }        catch (ServiceLocatorException sle)        {            MDC.put(Constants.USER_ID, profile.getUserID());            log.fatal(ErrorMessages.FAIL_TO_LOOKUP_DATASOURCE + " for " + Constants.DATASOURCE_EBANK, sle);            throw new SystemException(sle);        }        catch (SQLException se)        {            MDC.put(Constants.USER_ID, profile.getUserID());            log.error(ErrorMessages.FAIL_TO_CREATE_DATABASE_CONNECTION, se);            throw new SystemException(se);        }    }    //Close all of the data resources    protected void close()    {        closeStatement();        try        {            if (con != null)                con.close();        }        catch(SQLException se)        {            MDC.put(Constants.USER_ID, profile.getUserID());            log.error(ErrorMessages.FAIL_TO_CLOSE_DATABASE_CONNECTION, se);        }    }    //Close Statement belonging to this object only    protected void closeStatement()    {        closeStatement(this.ps);    }    //Close specified Statement    protected void closeStatement(Statement s)    {        try        {            if (s != null)                s.close();        }        catch(Exception se)        {            MDC.put(Constants.USER_ID, profile.getUserID());            log.error(ErrorMessages.FAIL_TO_CLOSE_DATABASE_STATEMENT, se);        }    }    public void setUserProfile(UserProfile profile)    {        this.profile = profile;    }}

⌨️ 快捷键说明

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