Tuesday, December 16, 2008

Using DataSources (with JDeveloper 10.1.3)

Struggling with opening a JDBC Connection via DataSources configured in OC4J/JDeveloper? Here's how it works:

First, start OC4J from outside JDeveloper. Set oc4jadmin's on first startup:

java -jar oc4j.jar

Default ports are 8888 for HTTP and 23791 for RMI.

If your data-sources.xml is not formd, add orion-application.xml to your application and add the following line:

<data-sources path="./data-sources.xml"></data-sources>

Finally, here's the code to get the connection via JNDI:

-- schnipp --

Properties env=new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.evermind.server.rmi.RMIInitialContextFactory"));
env.put(Context.SECURITY_PRINCIPAL ,"oc4jadmin");
env.put(Context.SECURITY_CREDENTIALS,"Your PW");
env.put(Context.PROVIDER_URL,"ormi://localhost:23791");
InitialContext ic=new InitialContext(env); // JNDI initial context
ds=(DataSource)ic.lookup(rb.getString("DataSource JNDI name"));

-- schnapp --

No comments:

Post a Comment