productclient.java

来自「J2EE编写企业应用教程(含源码)」· Java 代码 · 共 58 行

JAVA
58
字号
import java.util.*;import javax.naming.Context;import javax.naming.InitialContext;import javax.rmi.PortableRemoteObject;public class ProductClient {   public static void main(String[] args) {       try {           Context initial = new InitialContext();           Object objref = initial.lookup("MyProduct");           ProductHome home =                (ProductHome)PortableRemoteObject.narrow(objref,                                             ProductHome.class);           Product duke = home.create("123", "Ceramic Dog", 10.00);           System.out.println(duke.getDescription() + ": " + duke.getPrice());           duke.setPrice(14.00);           System.out.println(duke.getDescription() + ": " + duke.getPrice());           duke = home.create("456", "Wooden Duck", 13.00);           duke = home.create("999", "Ivory Cat", 19.00);           duke = home.create("789", "Ivory Cat", 33.00);           duke = home.create("876", "Chrome Fish", 22.00);           Product earl = home.findByPrimaryKey("876");           System.out.println(earl.getDescription() + ": " + earl.getPrice());           Collection c = home.findByDescription("Ivory Cat");           Iterator i = c.iterator();           while (i.hasNext()) {              Product product = (Product)i.next();              String productId = (String)product.getPrimaryKey();              String description = product.getDescription();              double price = product.getPrice();               System.out.println(productId + ": " + description + " " + price);           }           c = home.findInRange(10.00, 20.00);           i = c.iterator();           while (i.hasNext()) {              Product product = (Product)i.next();              String productId = (String)product.getPrimaryKey();              double price = product.getPrice();               System.out.println(productId + ": " + price);           }       } catch (Exception ex) {           System.err.println("Caught an exception." );           ex.printStackTrace();       }   } } 

⌨️ 快捷键说明

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