Example Client Application connecting to JNDI service
import java.util.*;
import java.rmi.*;
import java.io.*;
import javax.naming.*;
import.javax.ejb.*;
//this client demonstrates use of JNDI
public class Client{
public static InitialContext
ctx;
public static void main(String[] argv) {
try{
print("Conneting
to a JNDI service ....");
ctx = new InitialContext();
System.out.print("connected
successfully");
//add binding
String name = "mary";
String email="mary@fun.com";
ctx.bind(name, email);
//lookup binding
String s = (String) ctx.lookup("mary");
print(s);
//delete binding
ctx.unbind("mary");
//close
ctx.close();
}catch(CommunicationException e) { //failed to connect}
}}
|