【问题标题】:How to get OracleConnection in Oracle 12c WebLogic without specify IP weblogic server using Java Spring Framework如何使用 Java Spring Framework 在 Oracle 12c WebLogic 中获取 OracleConnection 而无需指定 IP weblogic 服务器
【发布时间】:2018-11-09 03:31:17
【问题描述】:

我必须将 WAR 部署到 oracle 12c weblogic 服务器并访问它的数据源。但我会将它部署在几个具有不同 IP 的 weblogic 服务器中。有没有办法在不指定 weblogic 本身的 ip 的情况下连接到 weblogic 数据源?假设 WAR 部署在同一个 weblogic 服务器中并且需要访问它在 weblogic 中指定的数据源?

我可以得到oracle连接,但必须指定IP。这是我的代码:

try{
    String urlparam = "t3://101.102.103.104:7001";
    String datasourceparam = "jdbc/devtest";

    Hashtable env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
    env.put(Context.PROVIDER_URL, urlparam);

    Context context=new InitialContext( env );
    ds=(javax.sql.DataSource) context.lookup (datasourceparam);
    conn=(OracleConnection) ds.getConnection();
    System.out.println("Connection object details : " + conn);
}
catch(Exception ex){
      ex.printStackTrace();
 }

如果我使用这种方法,要部署到 5 个 weblogic 服务器,我必须生成 5 个不同的 WAR,只有不同的 IP weblogic 服务器。

请帮忙..

【问题讨论】:

    标签: java spring-mvc weblogic oracle12c


    【解决方案1】:

    事实证明,要查看它自己的数据源,我不能在我的 InitialContext 中包含哈希表环境。这样,它将自己获取指定的数据源。

    try {    
        String datasourceparam = "jdbc/devtest";
    
        Context context = new InitialContext();
        ds = (javax.sql.DataSource) context.lookup(datasourceparam);
        conn = (OracleConnection) ds.getConnection();
    } catch (Exception ex) {
        // handle the exception
        ex.printStackTrace();
    }
    

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      • 2016-11-25
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 2014-09-23
      相关资源
      最近更新 更多