[英]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.