简体   繁体   English

如何使用Java Spring Framework在不指定IP Weblogic服务器的情况下在Oracle 12c WebLogic中获取OracleConnection

[英]How to get OracleConnection in Oracle 12c WebLogic without specify IP weblogic server using Java Spring Framework

I have to deploy WAR to oracle 12c weblogic server and access it's datasource. 我必须将WAR部署到oracle 12c weblogic服务器并访问其数据源。 but i will deploy it in several weblogic server with different IP. 但我将其部署在具有不同IP的多个weblogic服务器中。 is there any way to get connection to weblogic datasource without specify ip of the weblogic itself? 没有指定weblogic本身的ip,有什么方法可以连接到weblogic数据源? assuming that the WAR is deployed in the same weblogic server and needed to access it's datasouce specified in the weblogic? 假设WAR部署在同一Weblogic服务器中,并且需要访问WAR在Weblogic中指定的数据源?

i can get oracle connection but must specify the IP. 我可以获得oracle连接,但必须指定IP。 here is my code : 这是我的代码:

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();
 }

If i use this method, to deploy to 5 weblogic servers, i have to generate 5 different WAR with only different IP weblogic server. 如果我使用此方法,要部署到5个weblogic服务器,则必须仅使用不同的IP weblogic服务器生成5个不同的WAR。

Please help.. 请帮忙..

It turns out that to look at it's own datasource, i mustn't include hashtable environment in my InitialContext. 事实证明,要查看它自己的数据源,我不能在InitialContext中包含哈希表环境。 this way, it will get specified datasource in itself. 这样,它将本身获得指定的数据源。

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.sql.SQLException:无法在设置自动提交的情况下回滚(JDBC with OracleConnection,Weblogic 12c) - java.sql.SQLException:Could not rollback with auto commit set on (JDBC with OracleConnection ,Weblogic 12c) 无法在Oracle Jdeveloper 12c中启动Integrated WebLogic Server - Can not start Integrated WebLogic server in Oracle Jdeveloper 12c 在32位Windows上具有Java EE 7的Oracle WebLogic Server 12c:哪个SDK? - Oracle WebLogic Server 12c with Java EE 7 on 32-bit Windows: Which SDK? Weblogic 12c上的Spring SAML - Spring SAML on Weblogic 12c 如何在Weblogic 12c(12.1.3)上部署Spring Boot应用程序? - How to deploy a Spring Boot application on Weblogic 12c (12.1.3)? Java WebService在Weblogic 12c中不“可见” - Java WebService is not “visible” in Weblogic 12c Weblogic 12c和Java EE 7功能 - Weblogic 12c and Java EE 7 Features 如何运行Weblogic 12c服务器的应用程序客户端容器 - How to run application client container of weblogic 12c server weblogic.j2ee.dd.xml.AnnotationProcessException(基于weblogic 12c和spring5 java的配置) - weblogic.j2ee.dd.xml.AnnotationProcessException ( weblogic 12c and spring5 java based config) 如何在java和weblogic 12c中正确执行相互身份验证? - How to properly perform mutual authentication in java and weblogic 12c?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM