jndi.java

来自「weblogic +jbulider综合开发」· Java 代码 · 共 84 行

JAVA
84
字号
package jndi;import javax.naming.*;import java.util.Hashtable;class JNDI {  static Context ctx = null;  public JNDI() {  }  public static void bind(String name, String object) {    Hashtable ht = new Hashtable();    ht.put(Context.INITIAL_CONTEXT_FACTORY,           "weblogic.jndi.WLInitialContextFactory");    ht.put(Context.PROVIDER_URL, "t3://localhost:7001");    try {      ctx = new InitialContext(ht);      // Use the context in your program      ctx.rebind(name, object);    }    catch (NamingException e) {      // a failure occurred          System.out.println(e);    }    finally {      try {        ctx.close();      }      catch (Exception e) {        e.printStackTrace();      }    }  }  public static Object lookUp(String name) {    Hashtable ht = new Hashtable();    ht.put(Context.INITIAL_CONTEXT_FACTORY,           "weblogic.jndi.WLInitialContextFactory");    ht.put(Context.PROVIDER_URL, "t3://localhost:7001");    try {      ctx = new InitialContext(ht);      // Use the context in your program      Object object = ctx.lookup(name);      return object;    }    catch (NamingException e) {      e.printStackTrace();    }    finally {      try {        ctx.close();      }      catch (Exception e) {        // a failure occurred          System.out.println(e);      }    }    return null;  }  public static void main(String args[]) {    String arg = args[0];    if(arg.equals("bind")){           System.out.println("bind begin...");       String bookName = "WebLogic introduction";       bind("bookname", bookName);           System.out.println("bind end");    }    if(arg.equals("lookup")){      System.out.println("lookup begin...");      String bookName;      bookName = (String)lookUp("bookname");      System.out.println("bookname is: "+bookName);          System.out.println("lookup end");    }  }}

⌨️ 快捷键说明

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