title: How to access JNDI data source defined in weblogic 10.3.6
body: <p>I have created a JNDI data-source using my weblogic console but I am not able to access the object from my web application. Below are the details</p>
  
  <p>In weblogic 10.3.6, I have given the JNDI name for datasource  as : <code>jdbc/mydb</code></p>
  
  <p>To get DB connection from my web application I have written this code in my web application:</p>
  
  <pre><code>Context initContext = new InitialContext();
  DataSource ds = (DataSource)initContext.lookup("java:/comp/env/jdbc/mydb");
  jndiConnection = ds.getConnection();
  </code></pre>
  
  <p>Earlier I was using Tomcat as server and I was able to get DB connection when I configured the resource details in the file <code>tomcat/conf/server.xml</code>, but when I am using started using weblogic server I am getting below error:</p>
  
  <pre><code>Cannot establish DB connection to JNDI:java:/comp/env/jdbc/mydb While trying to look up /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702. caused by: javax.naming.NameNotFoundException: While trying to look up /comp/env/jdbc/mydb in /app/webapp/sample.war/1811641702.; remaining name '/comp/env/jdbc/mydb'
  </code></pre>
  
  <p>I have tried the options mentioned in this link : <a href="https://stackoverflow.com/questions/6500632/how-to-lookup-jndi-resources-on-weblogic">How to lookup JNDI resources on WebLogic?</a> but still I am facing problems.</p>
  
  <p>Please let me know where I am doing mistake, what is the process of accessing the JNDI object.</p>