Your application also can use resource adapters directly instead of using them through a container-managed, application server environment. The following code example shows how your application can access an Oracle database directly using a resource adapter:
static public void main(String[] args) {
// Create a connection factory instance
OracleManagedConnectionFactory managedFactory =
new OracleManagedConnectionFactory();
managedFactory.setServerName("MyOracleServer");
managedFactory.setPortNumber("1521");
managedFactory.setSID("TEST");
JCAConnectionFactory factory = (JCAConnectionFactory)
managedFactory.createConnectionFactory();
// Get an InitialContext.
// Using File System JNDI Service Provider as an example
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:c:/ConnectionFactories");
Context connectorContext = new InitialContext(env);
// Bind the connection factory
connectorContext.bind("OracleConnectionFactory", factory);
connectorContext.rebind("OracleConnectionFactory", factory);
catch (Exception except) {
System.out.println("Error creating DataSource");
// Connect via the DataSource
// Get an InitialContext.
// Using File System JNDI Service Provider as an example
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL, "file:c:/ConnectionFactories");
Context connectorContext = new InitialContext(env);
// Lookup the connection factory
DataSource dataSource = (DataSource)
connectorContext.lookup("OracleConnectionFactory");
Connection connection = dataSource.getConnection("scott", "tiger");
catch (Exception except) {
System.out.println("Looking up connection factory");