?? savingsaccountclient.java
字號:
/* * * Copyright 2001 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */import java.util.*;import javax.naming.Context;import javax.naming.InitialContext;import javax.rmi.PortableRemoteObject;public class SavingsAccountClient { public static void main(String[] args) { try { Context initial = new InitialContext(); Object objref = initial.lookup("java:comp/env/ejb/SimpleSavingsAccount"); SavingsAccountHome home = (SavingsAccountHome)PortableRemoteObject.narrow(objref, SavingsAccountHome.class); SavingsAccount duke = home.create("123", "Duke", "Earl", 0.00); duke.credit(88.50); duke.debit(20.25); double balance = duke.getBalance(); System.out.println("balance = " + String.valueOf(balance)); duke.remove(); SavingsAccount joe = home.create("836", "Joe", "Jones", 0.00); joe.credit(34.55); SavingsAccount jones = home.findByPrimaryKey("836"); jones.debit(2.00); balance = jones.getBalance(); System.out.println("balance = " + String.valueOf(balance)); SavingsAccount pat = home.create("456", "Pat", "Smith", 0.00); pat.credit(44.77); SavingsAccount john = home.create("730", "John", "Smith", 0.00); john.credit(19.54); SavingsAccount mary = home.create("268", "Mary", "Smith", 0.00); mary.credit(100.07); Collection c = home.findByLastName("Smith"); Iterator i=c.iterator(); while (i.hasNext()) { SavingsAccount account = (SavingsAccount)i.next(); String id = (String)account.getPrimaryKey(); double amount = account.getBalance(); System.out.println(id + ": " + String.valueOf(amount)); } c = home.findInRange(20.00, 99.00); i=c.iterator(); while (i.hasNext()) { SavingsAccount account = (SavingsAccount)i.next(); String id = (String)account.getPrimaryKey(); double amount = account.getBalance(); System.out.println(id + ": " + String.valueOf(amount)); } System.exit(0); } catch (InsufficientBalanceException ex) { System.err.println("Caught an InsufficientBalanceException: " + ex.getMessage()); } catch (Exception ex) { System.err.println("Caught an exception." ); ex.printStackTrace(); } } }
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -