2009-03-09 1 views
1

"java : comp/env/jdbc/MY_SQL_DS"가 작동하지 않습니다. 명명 예외 : NameNotFoundException이 발생합니다. 둘 다 "MY_SQL_DS"alone.name 예외를 다시 작동합니다. "java : comp/env/jdbc/MY_SQL_DS"또는 "MY_SQL_DS"또는 Java 내에서 DataSource를 참조 할 다른 항목은 무엇입니까?

나는 "MY_MailSession"라는 메일 세션에 대한 또 다른 JNDI를 생성하고 참조하는 규칙이 무엇인지 작동 (javax.mail.Session) ctx.lookup ("MY_MailSession") ...

처럼 참조 그런 다음 JDBC 데이터 소스를?

답변

0

나는 그것을 다음과 같은 방법으로 해결이 다른 사람들이 나중에 같은 문제/문제가 있습니다 희망을 ...

protected Connection getConnection() { 
      try { 
       if (connection == null || connection.isClosed()) { 
        if (dataSource == null) { 
         // impliziter Initial Context von WebLogic ApplicationServer Environment 
         java.util.Hashtable environment = new java.util.Hashtable(); 
         environment.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); 
         Context wlsic = new InitialContext(environment); 
         showJndiContext(wlsic, "", ""); 

         // logischer JNDI Rootcontext der Serverkomponente, kann mehrfach verwendet werden 
         Context ctx = (Context) wlsic.lookup("java:comp/env"); 
         showJndiContext(ctx, "", ""); 

         // weiter mit Resourcenpfad 
         dataSource = (DataSource) ctx.lookup("MY_SQL_DS"); 
        } 
        connection = dataSource.getConnection(); 
       } 
      } 
      catch (NamingException ne) { 
       ne.printStackTrace(); 
       log.error(ne); 
      } 
      catch (SQLException sqlEx) { 
       sqlEx.printStackTrace(); 
       log.error(sqlEx.getMessage()); 
      } 
      return connection; 
     } 

     public static void showJndiContext(Context ctx, String name, String space) { 
      if (null == name) 
       name = ""; 
      if (null == space) 
       space = ""; 

      try { 
       NamingEnumeration en = ctx.list(name); 
       while (en.hasMoreElements()) { 
        String delim = (null != name && 0 < name.length()) ? "/" : ""; 
        NameClassPair nc = (NameClassPair) en.next(); 
        System.out.println(space + name + delim + nc); 
        if (40 > space.length()) 
         showJndiContext(ctx, nc.getName(), " " + space); 
       } 
      } 
      catch (javax.naming.NamingException ex) { 
       //System.out.println(ex); 
      } 
     }