title: Access the DataSource from the stand alone application
body: <p>I have created the data source in Websphere server and its name is myDataSource(JNDI name is oracleDS). Now I want to access it through the stand alone application.</p>
  
  <p>I just wrote the bellow code to access the data sorce. </p>
  
  <pre><code>Hashtable&lt;String, String&gt; pdEnv = new Hashtable&lt;String, String&gt;();
  pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
  pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2809");
  
  Context initialContext = new InitialContext(pdEnv);
  
  DataSource dataSource = (DataSource) initialContext
                      .lookup("java:comp/env/jdbc/oracleDS");
  </code></pre>
  
  <p>But when I run the application I am getting the bellow exception.</p>
  
  <pre><code>Aug 6, 2013 11:33:41 PM null null
  SEVERE: javaAccessorNotSet
  javax.naming.ConfigurationException: Name space accessor for the java: name space has not been set. Possible cause is that the user is specifying a java: URL name in a JNDI Context method call but is not running in a J2EE client or server environment.
  </code></pre>
  
  <p>Please let me know do I have to do any configuration changes in websphere to access the data source or any other code level changes do I have to do?</p>
  
  <p>Please confirm me can we access the datasource from outside of the container(websphere)?</p>
  
  <p><strong>Update1:</strong></p>
  
  <p>I followd the way which PhilipJ mentioned. Then I am gtting the bellow exception.</p>
  
  <pre><code>SEVERE: Cannot get connection: javax.naming.NameNotFoundException: Context: LTC-VIRTUS-24WZNode01Cell/nodes/LTC-VIRTUS-24WZNode01/servers/server1, name: jdbc/oracleDS: First component in name oracleDS not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
  javax.naming.NameNotFoundException: Context: LTC-VIRTUS-24WZNode01Cell/nodes/LTC-VIRTUS-24WZNode01/servers/server1, name: jdbc/oracleDS: First component in name oracleDS not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
      at com.ibm.ws.naming.jndicos.CNContextImpl.mapNotFoundException(CNContextImpl.java:4365)
      at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1794)
      at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1749)
      at com.ibm.ws.naming.jndicos.CNContextImpl.lookupExt(CNContextImpl.java:1500)
      at com.ibm.ws.naming.jndicos.CNContextImpl.lookup(CNContextImpl.java:637)
      at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:165)
      at com.ibm.ws.naming.util.WsnInitCtx.lookup(WsnInitCtx.java:179)
      at javax.naming.InitialContext.lookup(InitialContext.java:436)
      at com.nyl.connection.ConnectionUtil.getConnection(ConnectionUtil.java:38)
      at com.nyl.main.Main.main(Main.java:9)
  Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
      at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:95)
      at com.ibm.WsnOptimizedNaming._NamingContextStub.resolve_complete_info(_NamingContextStub.java:506)
      at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2797)
      at com.ibm.ws.naming.jndicos.CNContextImpl$2.run(CNContextImpl.java:2793)
      at com.ibm.ws.naming.util.CommonHelpers.retry(CommonHelpers.java:763)
      at com.ibm.ws.naming.jndicos.CNContextImpl.cosResolve(CNContextImpl.java:2791)
      at com.ibm.ws.naming.jndicos.CNContextImpl.doLookup(CNContextImpl.java:1790)
      ... 8 more
  </code></pre>
  
  <p><strong>Update2:</strong></p>
  
  <p>I found the way to avoid the exception. The code should be bellow,</p>
  
  <pre><code>Hashtable&lt;String, String&gt; pdEnv = new Hashtable&lt;String, String&gt;();
  pdEnv.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
  pdEnv.put(Context.PROVIDER_URL, "iiop://localhost:2809");
  
  Context initialContext = new InitialContext();
  DataSource datasource = (DataSource) initialContext.lookup("oracleDS");
  
  if (datasource != null) {
  connection = datasource.getConnection("admin","admin");
  } else {
  LOGGER.info("Failed to lookup datasource.");
  }
  </code></pre>
  
  <p>But the problem here is I am giving the database credintials to creat the connection. I don't want to give it. Can any one please let me know how to create the connection without giving the database credintials?</p>