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

📄 userloader.java

📁 我在加拿大学习的一个比较复杂的在线银行程序.
💻 JAVA
字号:
package com.ebusiness.ebank.security;/** * <p>Title: </p> * <p>Description: This class is to load a new user through ...</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.ResultSet;import javax.sql.DataSource;import com.ebusiness.ebank.servicedelegate.ServiceLocator;import com.ebusiness.ebank.exception.SystemException;import com.ebusiness.ebank.util.Constants;public class UserLoader{    private DataSource ds;    private static UserLoader loader = new UserLoader();    private UserLoader(){}    public static UserLoader getInstance() {return loader;}    //Load UserProfile through data store. It may be a LDAP server    public UserProfile load(String userID, String[] roles) throws SystemException    {        try        {            UserPreference pref = getUserPreference(userID);            return new UserProfile(userID, pref.getLanguage(), roles);        }        catch (Exception e)        {            throw new SystemException(e);        }    }    private UserPreference getUserPreference(String userID) throws SystemException    {        UserPreference pref = null;        PreparedStatement ps = null;        Connection con = null;        try        {            if (ds == null )                ds = ServiceLocator.getInstance().getDataSource(Constants.DATASOURCE_EBANK);            con = ds.getConnection();            ps = con.prepareStatement("Select * from Preference where User_ID = ?");            ps.setString(1, userID);            ResultSet rs = ps.executeQuery();            pref = new UserPreference();            pref.setUserID(userID);            if (rs.next())                pref.setLanguage(rs.getString("language"));            else                pref.setLanguage("en"); //default to English        }        catch (Exception e)        {            throw new SystemException(e);        }        finally        {            try            {                if (ps != null)                   ps.close();                if (con != null)                   con.close();            }            catch (Exception e)            {                throw new SystemException(e);            }        }        return pref;    }}

⌨️ 快捷键说明

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