📄 startstudentclient.java
字号:
/*
*
* Copyright 2002 Author,Zhang Hongzhan. All Rights Reserved.
*
* This software is the proprietary information of Author.
*
*/
package sessionEntity;
import java.math.BigDecimal;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class StartStudentClient{
private static final String JNDI_NAME = "StartStudentEJB";
private static final String url = "t3://localhost:7001";
public static void main(String[] args) {
try{
// Get an InitialContext
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, url);
Context ctx = new InitialContext(env);
Object h=ctx.lookup(JNDI_NAME);
StartStudentHome startstudenthome=(StartStudentHome)
PortableRemoteObject.narrow(h,StartStudentHome.class);
StartStudent startstudent =startstudenthome.create();
String theStudent=startstudent.HelloStudent();
System.out.println("My EJB said:"+theStudent);
System.out.println("Finding All the Students in grade 20:");
try {
Collection c = startstudent.getAllStudents(20);
if (c.isEmpty()) {
System.err.println("No Students were found in grade 20.");
} else {
Iterator it = c.iterator();
while (it.hasNext()) {
Student s = (Student) narrow(it.next(), Student.class);
System.err.println("Found student named: "+s.getName()+
" in grade 20.");
}
System.out.println("");
}
} catch (Exception e) {
System.err.println("Unable to find students in grade 20.");
//e.printStackTrace();
//throw e;
}
/*BigDecimal param = new BigDecimal ("100.00");
Collection amount = currencyHelloWorld.dollarToRMB(param);
System.out.println("100 dollar = "+amount+" RMB");
*/
}catch(Exception ex) {
System.err.println("Caught an unexpected exception!");
//ex.printStackTrace();
}
}
private static void log(String s) {
System.out.println(s);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -