How to lookup JNDI resources on WebLogic?

前端 未结 4 584
刺人心
刺人心 2020-11-30 08:27

I deployed a legacy application on WebLogic 11g. The application has the following code:

 Context context = new InitialContext();
 dataSource = (javax.sql.Da         


        
4条回答
  •  自闭症患者
    2020-11-30 08:49

    I just had to update legacy Weblogic 8 app to use a data-source instead of hard-coded JDBC string. Datasource JNDI name on the configuration tab in the Weblogic admin showed: "weblogic.jdbc.ESdatasource", below are two ways that worked:

          Context ctx = new InitialContext();
          DataSource dataSource;
    
          try {
            dataSource = (DataSource) ctx.lookup("weblogic.jdbc.ESdatasource");
            response.getWriter().println("A " +dataSource);
          }catch(Exception e) {
            response.getWriter().println("A " + e.getMessage() + e.getCause());
          }
    
          //or
    
          try {
            dataSource = (DataSource) ctx.lookup("weblogic/jdbc/ESdatasource");
            response.getWriter().println("F "+dataSource);
          }catch(Exception e) {
            response.getWriter().println("F " + e.getMessage() + e.getCause());
          }
    
          //use your datasource
          conn = datasource.getConnection();
    

    That's all folks. No passwords and initial context factory needed from the inside of Weblogic app.

提交回复
热议问题