亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? accountbean.java

?? EJB_原代碼多例-好好東西啊
?? JAVA
字號:
package com.wiley.compBooks.roman.entity.account;

import java.sql.*;
import javax.naming.*;
import javax.ejb.*;
import java.util.*;
import java.rmi.RemoteException;


/**
 * Demonstration Bean-Managed Persistent Entity Bean.
 * This Entity Bean represents a Bank Account.
 */
public class AccountBean implements EntityBean {

	protected EntityContext ctx;

	// Bean-managed state fields
	public String accountID;	// PK
	public String ownerName;
	public double balance;

	// Environment properties the bean was deployed with
	public Properties env;

	public AccountBean() {
		System.out.println("New Bank Account Entity Bean Java Object created by EJB Container.");
	}

	//
	// Business Logic Methods
	//

	/**
	 * Deposits amt into account.
	 */
	public void deposit(double amt) throws AccountException {
		System.out.println("deposit(" + amt + ") called.");
		
		balance += amt;
	}

	/**
	 * Withdraws amt from bank account.
	 * @throw AccountException thrown in amt < available balance
	 */
	public void withdraw(double amt) throws AccountException {
		System.out.println("withdraw(" + amt + ") called.");

		if (amt > balance) {
			throw new AccountException("Your balance is " + balance + "!  You cannot withdraw " + amt + "!");
		}

		balance -= amt;
	}

	// Getter/setter methods on Entity Bean fields

	public double getBalance() {
		System.out.println("getBalance() called.");
		return balance;
	}

	public void setOwnerName(String name) {
		System.out.println("setOwnerName() called.");
		ownerName = name;
	}
	
	public String getOwnerName() {
		System.out.println("getOwnerName() called.");
		return ownerName;
	}
	
	public String getAccountID() {
		System.out.println("getAccountID() called.");
		return accountID;
	}
	
	public void setAccountID(String id) {
		System.out.println("setAccountID() called.");
		this.accountID = id;
	}
	
	//
	// EJB-required methods
	//

	/**
	 * Called by Container.  Implementation can acquire
	 * needed resources.
	 */
	public void ejbActivate() throws RemoteException {
		System.out.println("ejbActivate() called.");
	}

	/**
	 * Removes entity bean data from the database.
	 * Corresponds to when client calls home.remove().
	 */
	public void ejbRemove() throws RemoteException {
		System.out.println("ejbRemove() called.");

		/*
		 * Remember that an entity bean class can be used to
		 * represent different data instances.  So how does
		 * this method know which instance in the database
		 * to delete?
		 *
		 * The answer is to query the container by calling
		 * the entity context object.  By retrieving the
		 * primary key from the entity context, we know
		 * which data instance, keyed by the PK, that we
		 * should delete from the DB.
		 */
                AccountPK pk = (AccountPK) ctx.getPrimaryKey();
                String id = pk.accountID;

                PreparedStatement pstmt = null;
                Connection conn = null;
                try {
                        /*
			 * 1) Acquire a new JDBC Connection
			 */
                        conn = getConnection();

                        /*
			 * 2) Remove account from the DB
			 */
                        pstmt = conn.prepareStatement("delete from accounts where id = ?");
                        pstmt.setString(1, id);
			
			/*
			 * 3) Throw a system-level exception if something
			 * bad happened.
			 */
			if (pstmt.executeUpdate() == 0) {
                	        throw new RemoteException("Account " + pk + " failed to be removed from the database");
			}
                }
                catch (SQLException ex) {
			throw new RemoteException(ex.toString());
                }
                finally {
                        /*
			 * 4) Release the DB Connection
			 */
                        try {
                                if (pstmt != null) pstmt.close();
			}
			catch (Exception e) { }
			try {
                                if (conn != null) conn.close();
                        }
                        catch (Exception e) { }
                }
	}

	/**
	 * Called by Container.  Releases held resources for
	 * passivation.
	 */
	public void ejbPassivate() throws RemoteException {
		System.out.println("ejbPassivate () called.");
	}

	/**
	 * Called by the container.  Updates the in-memory entity
	 * bean object to reflect the current value stored in
	 * the database.
	 */
	public void ejbLoad() throws RemoteException {
		System.out.println("ejbLoad() called.");

		/*
		 * Again, query the Entity Context to get the current
		 * Primary Key, so we know which instance to load.
		 */
		AccountPK pk = (AccountPK) ctx.getPrimaryKey();
		String id = pk.accountID;

		PreparedStatement pstmt = null;
                Connection conn = null;
		try {
			/*
			 * 1) Acquire a new DB Connection
			 */
			conn = getConnection();

			/*
			 * 2) Get account from the DB, querying
			 *    by account ID
			 */
			pstmt = conn.prepareStatement("select ownerName, balance from accounts where id = ?");
			pstmt.setString(1, id);
			ResultSet rs = pstmt.executeQuery();
			rs.next();
			ownerName = rs.getString("ownerName");
			balance = rs.getDouble("balance");
		}
		catch (SQLException ex) {
			throw new RemoteException("Account " + pk + " failed to load from database", ex);
		}
		finally {
			/*
			 * 3) Release the DB Connection
			 */
			try {
				if (pstmt != null) pstmt.close();
			}
			catch (Exception e) { }
			try {
				if (conn != null) conn.close();
			}
			catch (Exception e) { }
		}

	}

	/**
	 * Called from the Container.  Updates the database
	 * to reflect the current values of this in-memory
	 * entity bean instance.
	 */
	public void ejbStore() throws RemoteException {
		System.out.println("ejbStore() called.");

		PreparedStatement pstmt = null;
                Connection conn = null;
		try {
			/*
			 * 1) Acquire a new DB Connection
			 */
			conn = getConnection();

			/*
			 * 2) Store account in DB
			 */
			pstmt = conn.prepareStatement("update accounts set ownerName = ?, balance = ? where id = ?");
			pstmt.setString(1, ownerName);
			pstmt.setDouble(2, balance);
			pstmt.setString(3, accountID);
			pstmt.executeUpdate();

		}
		catch (SQLException ex) {
			throw new RemoteException("Account " + accountID + " failed to save to database", ex);
		}
		finally {
			/*
			 * 3) Release the DB Connection
			 */
			try {
				if (pstmt != null) pstmt.close();
			}
			catch (Exception e) { }
			try {
				if (conn != null) conn.close();
			}
			catch (Exception e) { }
		}
	}

	/**
	 * Called by the container.  Associates this bean
	 * instance with a particular context.  We can query
	 * the bean properties which customize the bean here.
	 */
	public void setEntityContext(EntityContext ctx) throws RemoteException {
		System.out.println("setEntityContext called");
		this.ctx = ctx;

		env = ctx.getEnvironment();
	}

	/**
	 * Called by Container.  Disassociates this bean
	 * instance with a particular context environment.
	 */
	public void unsetEntityContext() throws RemoteException {
		System.out.println("unsetEntityContext called");
		this.ctx = null; 
		this.env = null;
	}

	/**
	 * Called after ejbCreate().  Now, the Bean can retrieve
	 * its EJBObject from its context, and pass it as
	 * a 'this' argument.
	 */
	public void ejbPostCreate(String accountID, String ownerName) throws RemoteException {
	}

	/**
	 * This is the initialization method that corresponds to the
	 * create() method in the Home Interface.
	 *
	 * When the client calls the Home Object's create() method,
	 * the Home Object then calls this ejbCreate() method.
	 *
	 * @return The primary key for this account
	 */
	public AccountPK ejbCreate(String accountID, String ownerName) throws CreateException, RemoteException {

	  PreparedStatement pstmt = null;
	  Connection conn = null;
	  try {
		System.out.println("ejbCreate() called.");
		this.accountID = accountID;
		this.ownerName = ownerName;
		this.balance = 0;

		/*
		 * Acquire DB connection
		 */
		conn = getConnection();
	
		/*
		 * Insert the account into the database
		 */
		pstmt = conn.prepareStatement("insert into accounts (id, ownerName, balance) values (?, ?, ?)");
		pstmt.setString(1, accountID);
		pstmt.setString(2, ownerName);
		pstmt.setDouble(3, balance);
		pstmt.executeUpdate();

		/*
		 * Generate the Primary Key and return it
		 */
		return new AccountPK(accountID);
	  }
	  catch (Exception e) {
		throw new CreateException(e.toString());
	  }
	  finally {
		/*
		 * Release DB Connection for other beans
		 */
		try {
			pstmt.close();
		}
		catch (Exception e) { }
		try {
			conn.close();
		}
		catch (Exception e) { }
	  }
	}

	/**
	 * Finds a Account by its primary Key
	 */
	public AccountPK ejbFindByPrimaryKey(AccountPK key) throws FinderException, RemoteException {
	  PreparedStatement pstmt = null;
          Connection conn = null;
	  try {
		System.out.println("ejbFindByPrimaryKey(" + key + ") called");

		/*
		 * Acquire DB connection
		 */
		conn = getConnection();
		
		/*
		 * Find the Entity in the DB
		 */
		pstmt = conn.prepareStatement("select id from accounts where id = ?");
		pstmt.setString(1, key.toString());
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		
		/*
		 * No errors occurred, so return the Primary Key
		 */
		return key;
	  }
	  catch (Exception e) {
		throw new FinderException(e.toString());
	  }
	  finally {
		/*
		 * Release DB Connection for other beans
		 */
		try {
			pstmt.close();
		}
		catch (Exception e) { }
		try {
			conn.close();
		}
		catch (Exception e) { }
	  }
	}

	/**
	 * Finds a Account by its Name
	 */
	public Enumeration ejbFindByOwnerName(String name) throws FinderException, RemoteException {
	  PreparedStatement pstmt = null;
	  Connection conn = null;
	  Vector v = new Vector();

	  try {
		System.out.println("ejbFindByOwnerName(" + name + ") called");
		
		/*
		 * Acquire DB connection
		 */
		conn = getConnection();
		
		/*
		 * Find the primary keys in the DB
		 */
		pstmt = conn.prepareStatement("select id from accounts where ownerName = ?");
		pstmt.setString(1, name);
		ResultSet rs = pstmt.executeQuery();

		/*
		 * Insert every primary key found into a vector
		 */
		while (rs.next()) {
			String id = rs.getString("id");
			v.addElement(new AccountPK(id));
		}
		
		/*
		 * Return an enumeration of found primary keys
		 */
		return v.elements();
	  }
	  catch (Exception e) {
		throw new FinderException(e.toString());
	  }
	  finally {
		/*
		 * Release DB Connection for other beans
		 */
		try {
			pstmt.close();
		}
		catch (Exception e) { }
		try {
			conn.close();
		}
		catch (Exception e) { }
	  }
	}

	public static final String JDBC_URL = "JDBC_URL";
	
	/**
	 * Gets current connection to the connection pool.
	 *
	 * Note: In the future, once vendors have adopted JDBC 2.0,
	 * the preferred method for retrieving a JDBC Connection is
	 * through JNDI.
	 *
	 * Assumes that environment properties contains a property
	 * named "user" and "password" if authentication is desired.
	 * These environment properties are retrieved from the
	 * EntityContext object during setEntityContext().
	 *
	 * @return                  Connection
	 * @exception               java.sql.SQLException
	 *
	 */
	public Connection getConnection() throws SQLException {
		String jdbcURL = (String) env.get(JDBC_URL);
	
		// For debugging...	
		// String drivers = (String) env.get("jdbc.drivers");
		// System.out.println(jdbcURL + ", " + drivers);
		// DriverManager.setLogStream(System.out);
	
		return DriverManager.getConnection(jdbcURL, env);
	}

//	static {
//		try {	
//			new weblogic.jdbc.jts.Driver();
//			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//		}
//		catch (Exception e) {
//			e.printStackTrace();
//		}
//	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
97精品久久久午夜一区二区三区| 色综合天天综合网天天狠天天 | 久久久不卡网国产精品一区| 韩国成人精品a∨在线观看| 精品噜噜噜噜久久久久久久久试看| 精品影院一区二区久久久| 国产日韩欧美亚洲| 91伊人久久大香线蕉| 亚洲成人综合视频| 日韩欧美资源站| 国产成人免费视频精品含羞草妖精| 中文字幕日韩av资源站| 91精品办公室少妇高潮对白| 婷婷亚洲久悠悠色悠在线播放| 日韩一卡二卡三卡四卡| 精品一区二区三区在线播放| 欧美—级在线免费片| 91官网在线免费观看| 天天影视涩香欲综合网| 久久综合九色综合97_久久久| 成人av网址在线观看| 一区二区三区在线播放| 日韩美一区二区三区| 成人福利视频在线看| 亚洲超碰97人人做人人爱| 精品国产91乱码一区二区三区| 国产精品91一区二区| 亚洲综合偷拍欧美一区色| 日韩美女在线视频| www.亚洲在线| 日本成人中文字幕在线视频| 国产亚洲一区二区三区四区 | 久久久天堂av| 99精品黄色片免费大全| 日本欧美一区二区三区乱码| 久久久久九九视频| 日本韩国欧美在线| 久久超碰97中文字幕| 亚洲丝袜制服诱惑| 精品久久久久久综合日本欧美| 99久久久久久| 久久精品av麻豆的观看方式| 亚洲欧洲综合另类| 亚洲精品一区二区三区香蕉| 色噜噜夜夜夜综合网| 国产美女一区二区三区| 亚洲高清在线精品| 国产精品拍天天在线| 欧美一级黄色片| 色诱视频网站一区| 国产一区二区在线影院| 性做久久久久久久久| 国产精品久久久99| 精品少妇一区二区三区在线播放 | 99国产精品久| 精品亚洲porn| 午夜av一区二区三区| 日韩美女视频一区| 久久精品无码一区二区三区| 欧美另类一区二区三区| 成人午夜电影网站| 日本va欧美va精品| 亚洲精品国产无天堂网2021| 国产农村妇女毛片精品久久麻豆| 欧美一区二区三区喷汁尤物| 色吧成人激情小说| 成av人片一区二区| 久久99国内精品| 日韩高清国产一区在线| 亚洲精品中文在线影院| 亚洲国产岛国毛片在线| 欧美精品一区二区三区一线天视频| aaa国产一区| 国产一区二区三区| 老色鬼精品视频在线观看播放| 亚洲高清不卡在线观看| 亚洲欧美偷拍卡通变态| 国产欧美一区二区精品婷婷| 精品成人一区二区三区| 91精品啪在线观看国产60岁| 欧美色偷偷大香| 91久久久免费一区二区| 99国产一区二区三精品乱码| 成人福利电影精品一区二区在线观看| 韩国三级电影一区二区| 久久精品国产精品亚洲精品 | 亚洲444eee在线观看| 亚洲人吸女人奶水| 欧美激情中文不卡| 久久久国产精华| 精品福利二区三区| 精品国产一区久久| 欧美日韩国产电影| 色婷婷综合久久久久中文一区二区| 国产成人免费视频网站| 国产高清亚洲一区| 国产精品一区三区| 国产乱码精品一区二区三区五月婷 | 国产欧美视频一区二区| 久久久久久黄色| 国产欧美精品一区二区色综合| 久久精品人人做人人综合 | 中文字幕不卡三区| 中文乱码免费一区二区| 中文字幕成人在线观看| 国产精品美女久久久久久久久久久| 国产清纯白嫩初高生在线观看91 | 久久久久久久久久久久久女国产乱| 精品三级av在线| 精品99999| 国产亚洲精品bt天堂精选| 国产香蕉久久精品综合网| 欧美国产激情一区二区三区蜜月| 中文幕一区二区三区久久蜜桃| 亚洲欧洲av另类| 亚洲精品国产a| 亚洲高清一区二区三区| 日本免费在线视频不卡一不卡二| 六月婷婷色综合| 国产一区二区不卡在线| 成人高清视频免费观看| 色婷婷综合久久久中文一区二区| 欧美揉bbbbb揉bbbbb| 91精品国产91久久久久久一区二区 | 国产成人免费高清| 99视频在线精品| 欧美性淫爽ww久久久久无| 在线综合视频播放| 欧美va亚洲va在线观看蝴蝶网| 欧美大片拔萝卜| 日本一区二区免费在线观看视频| 国产精品少妇自拍| 亚洲一区在线看| 亚洲国产成人av网| 日本特黄久久久高潮| 极品少妇xxxx偷拍精品少妇| 成人妖精视频yjsp地址| 91亚洲精品久久久蜜桃| 欧美日韩综合在线| 欧美三级中文字幕| 日韩欧美色电影| 国产精品水嫩水嫩| 亚洲国产欧美一区二区三区丁香婷| 蜜臀久久99精品久久久画质超高清 | 亚洲国产精品精华液网站| 久久精品99国产精品| 国产呦萝稀缺另类资源| av日韩在线网站| 欧美色精品天天在线观看视频| 精品国精品自拍自在线| 国产精品久久久久久妇女6080| 亚洲一级电影视频| 亚洲bt欧美bt精品| 国产精品影视天天线| 日本韩国欧美三级| 精品1区2区在线观看| 曰韩精品一区二区| 精品一区二区三区在线视频| 91在线视频18| 欧美成人性福生活免费看| 日韩理论片一区二区| 日本欧美在线观看| 99精品国产热久久91蜜凸| 欧美一级欧美三级| √…a在线天堂一区| 蜜桃一区二区三区在线观看| 99久久伊人精品| 精品美女一区二区| 一区二区久久久久| 国产精品123| 在线成人午夜影院| 国产精品久久久久久久久果冻传媒| 日日噜噜夜夜狠狠视频欧美人| 成人夜色视频网站在线观看| 欧美一区二区在线播放| 亚洲色图欧美在线| 精品综合免费视频观看| 欧洲国产伦久久久久久久| 久久久久久久久久久黄色| 视频在线观看91| 波多野结衣欧美| 精品国产乱码久久久久久久| 亚洲一区自拍偷拍| 成人成人成人在线视频| 欧美成人一区二区三区片免费| 一区二区三区日韩欧美| 国产精品性做久久久久久| 91.xcao| 亚洲欧洲中文日韩久久av乱码| 国产一区二三区好的| 91精品啪在线观看国产60岁| 亚洲精品免费视频| 丁香桃色午夜亚洲一区二区三区| 欧美一区二区三区思思人| 一区二区三区四区在线| 成人精品一区二区三区中文字幕| 日韩欧美一级二级三级| 午夜久久久久久久久久一区二区| 91亚洲国产成人精品一区二三 | 久久精品国产99久久6|