获取AM指定的JDBC Datasource

 

概述
本文主要描述如如何在ADF中可以获取AM中指定的JDBC Datasource。

实现
1、创建ADF应用,为Model添加数据库连接

 

2、创建Application Module,在Configurations中选择Local,修改“Connection Type”为JDBC Datasource方式

3、AM的实现类中添加如下代码:

import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import oracle.jbo.client.Configuration; import weblogic.jdbc.common.internal.RmiDataSource; …… public void getCurrentAMDatasource() { Context ctx; try { ctx = new InitialContext(); RmiDataSource ds = (RmiDataSource)ctx.lookup((String)this.getSession().getEnvironment().get(Configuration.DB_CONNECTION_PROPERTY)); System.out.println(ds.getPoolName()); System.out.println(ds.getJNDINames().length); System.out.println(ds.getJNDINames()[0]); } catch (NamingException e) { e.printStackTrace(); } } 

 

4、将该方法发布到Client Interface

5、在ViewController项目中创建新页面,拖动按钮到该页面,将按钮的ActionListener绑定到发布成为Client Interface的方法

6、保存并运行应用,在控制台打印出的结果如下:

[09:34:31 AM] Application Deployed Successfully. [09:34:31 AM] The following URL context root(s) were defined and can be used as a starting point to test your application: [09:34:31 AM] http://10.213.246.232:7101/howtogetdatasource-ViewController-context-root [09:34:31 AM] Elapsed time for deployment: 26 seconds Run startup time: 26203 ms.[09:34:31 AM] ---- Deployment finished. ---- [Application howtogetdatasource deployed to Server Instance IntegratedWebLogicServer] Target URL -- http://127.0.0.1:7101/howtogetdatasource-ViewController-context-root/faces/main.jspx howto 1 jdbc/howtoDS 

本文转自Oracle Seeker:http://oracleseeker.com/2009/12/08/adf_am_jdbc_datasource_jndi/

你可能感兴趣的:(jdbc,Module,application,import,interface,Deployment)