Adding, Replacing, Removing, and Renaming a Binding in the Naming Service - Java JNDI

Java examples for JNDI:Name

Description

Adding, Replacing, Removing, and Renaming a Binding in the Naming Service

Demo Code

import javax.naming.Context;
import javax.naming.NamingException;

public class Main {
  public static void main(String[] argv) {
    try {/*from  w ww . ja  v a2 s.co  m*/
      Context ctx = null;
      // Add a binding.
      ctx.bind("Name", new SampleObjectImpl());

      // Replace a binding.
      ctx.rebind("Name", new SampleObjectImpl());

      // Remove a binding.
      ctx.unbind("Name");

      // Rename a binding.
      ctx.rename("Name", "NewSample");
    } catch (NamingException e) {
    }
  }
}
class SampleObjectImpl{}

Related Tutorials