title: Error when loading datasource
body: <p>So I recently have started working in a new proyect. These guys have the Datasource connection declared this way:</p>
  
  <pre><code>Context init = new InitialContext();
  Context context = (Context) init.lookup("java:comp/env");
  ds = (DataSource)context.lookup("jdbc/WhateverDS");
  </code></pre>
  
  <p>I don't know why have they declared it this way. I've had always seen it like this:</p>
  
  <pre><code>DataSource ds = new InitialContext().lookup("java:comp/env/jdbc/WhateverDS");
  </code></pre>
  
  <p>First of all do you guys know why would they do it in two steps?</p>
  
  <p>My second question is that sometimes we get the following error, and if it may have something to do with the code above:</p>
  
  <pre><code>Caused by: javax.naming.NameNotFoundException: The name comp/env is not bound in this context
      at org.apache.naming.NamingContext.lookup(NamingContext.java:818)
      at org.apache.naming.NamingContext.lookup(NamingContext.java:166)
      at org.apache.naming.SelectorContext.lookup(SelectorContext.java:157)
      at javax.naming.InitialContext.lookup(InitialContext.java:411)
      ... 19 more
  </code></pre>
  
  <p>We are using MySQL over Tomcat using jdbc.</p>
  
  <p>Edit: 
  They have nothing about the DB declared in web.xml.
  The context.xml (among other parameters) looks like this:</p>
  
  <pre><code>Resource driverClassName="com.mysql.jdbc.Driver"
              name="jdbc/WhateverDS"
              type="javax.sql.DataSource"
              url="jdbc:mysql://localhost:3306/someDB"
  </code></pre>