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

📄 client.java

📁 EJB应用开发详解配套源代码.rar
💻 JAVA
字号:
import javax.naming.InitialContext;import javax.naming.NamingException;import javax.naming.Context;import java.rmi.RemoteException;import javax.ejb.RemoveException;import javax.ejb.CreateException;import javax.ejb.FinderException;import java.util.Enumeration;import java.util.Hashtable;import javax.rmi.PortableRemoteObject; /** * CMP Client for JavaWorld article - 'The Art of EJB Deployment' */public class Client {    private static ProfileHome ph = null;    private static Profile p = null;    // If Websphere...    //private static ProfilePK pk = null;    public static void main(String[] args) {	Hashtable hash = new Hashtable();		// Use for Weblogic 6.0	hash.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");	hash.put(Context.PROVIDER_URL, "t3://localhost:7001");		// Uncomment if using Websphere 3.5	//env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.ejs.ns.jndi.CNInitialContextFactory");	//env.put(Context.PROVIDER_URL, "iiop://localhost:900");	// Uncomment if using JBOSS 2.2.1	//env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");	//env.put("java.naming.provider.url", "localhost:1099");			try {	    InitialContext ic = new InitialContext( hash );	    	    System.out.println("Got initial context...");	    	    Object ref = ic.lookup("profile/ProfileHome");	    	    System.out.println("Looked-up home interface...");	    	    ph = (ProfileHome) PortableRemoteObject.narrow( ref, ProfileHome.class );	    	    // If WebSphere...	    //pk = new ProfilePK();	    //pk.profile = "jbravo";	    try { 		p = ph.findByPrimaryKey( "jbravo" );		// If Websphere...		//p = ph.findByPrimaryKey( pk );	    } catch (javax.ejb.ObjectNotFoundException nex) {		p = ph.create(1, "Bravo", "Johnny");		if ( p == null ) {		    nex.printStackTrace();		    return;		}	    }	    	    System.out.println("*** Profile Credentials ***");	    System.out.println("ID: " + p.getProfile() );	    System.out.println("First Name: " + p.getFname() );	    System.out.println("Last Name: " + p.getLname() );	    System.out.println("ProfileID: " + p.getProfile() );	    	    System.out.println("\nDONE!");	} catch (Exception e) {	    e.printStackTrace();	}    }}

⌨️ 快捷键说明

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