Overview
This document describes how to obtain the JDBC datasource specified in AM in the ADF.
Implementation
1. Create an ADF application and add a database connection for the model.
2. Create an application module, select local in deployments, and change "connection type" to the JDBC datasource mode.
3. Add the following code to the implementation class of AM:
Import javax. naming. context; <br/> Import javax. naming. initialcontext; </P> <p> Import javax. naming. namingexception; <br/> Import oracle. jbo. client. configuration; <br/> Import weblogic. JDBC. common. internal. rmidatasource; <br/> ...... <Br/> Public void getcurrentamdatasource () {<br/> context CTX; <br/> try {<br/> CTX = new initialcontext (); <br/> rmidatasource DS = <br/> (rmidatasource) CTX. lookup (string) This. getsession (). getenvironment (). get (configuration. db_connection_property); <br/> system. out. println (Ds. getpoolname (); <br/> system. out. println (Ds. getjndinames (). length); <br/> system. out. println (Ds. getjndinames () [0]); <br/>} catch (namingexception e) {<br/> E. printstacktrace (); <br/>}< br/>}
4. Publish the method to the client interface
5. Create a page in the viewcontroller project, drag the button to the page, and bind the actionlistener of the button to the method for publishing the interface to the client.
6. Save and run the application. The result displayed on the console is as follows:
[09:34:31 am] Application deployed successfully. <br/> [09:34:31 am] the following URL context root (s) were defined and can be used as a starting point to test your application: <br/> [09:34:31 am] http: // 10.213.246.133: 7101/howtogetdatasource-viewcontroller-context-root <br/> [09:34:31 am] elapsed time for deployment: 26 seconds <br/> RUN startup time: 26203 Ms. [09:34:31 am] ---- deployment finished. ---- </P> <p> [Application howtogetdatasource deployed to server instance integratedweblogicserver] </P> <p> Target URL -- http: // 127.0.0.1: 7101/howtogetdatasource-viewcontroller-context-root/faces/main. jspx <br/> howto <br/> 1 <br/> JDBC/howtods
This article is transferred from Oracle Seeker: http://oracleseeker.com/2009/12/08/adf_am_jdbc_datasource_jndi/