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

📄 entitybeanclienttest.java

📁 JAVA编程百例书中各章节的所有例子的源代码,包括套接字编程
💻 JAVA
字号:
package ch05.section09;

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Enumeration;
import ch05.section08.*;

public class EntityBeanClientTest {

  public static void main(String[] args) {
    Account account = null;
    try {

      Context ctx = new InitialContext(System.getProperties());
      AccountHome home = (AccountHome) ctx.lookup("AccountHome");
      home.create("123-456-7890", "John Smith");
      Enumeration e = home.findByOwnerName("John Smith");
      if (e != null) {
        account = (Account) e.nextElement();
      }
      else {
        throw new Exception("Could not find account");
      }
      System.out.println("Initial Balance = " + account.getBalance());
      account.deposit(100);
      System.out.println("After depositing 100, account balance = " +
                         account.getBalance());
      PKClass pk = (PKClass) account.getPrimaryKey();
      account = null;
      account = home.findByPrimaryKey(pk);
      System.out.println("Found account with ID " + pk + ".  Balance = " +
                         account.getBalance());
      System.out.println("Now trying to withdraw $150, which is more than is currently available.  This should generate an exception..");
      account.withdraw(150);

    }
    catch (Exception e) {
      System.out.println("Caught exception!");
      e.printStackTrace();
    }
    finally {
      try {
        System.out.println("Destroying account..");
        if (account != null) {
          account.remove();
        }
      }
      catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
}

⌨️ 快捷键说明

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