title: Glassfish jdbc/database lookup failed
body: <p>I hope I am not asking a duplicate question just because I was unable to find an answer.
  I am getting this error:</p>
  
  <p><em>javax.naming.NamingException: Lookup failed for 'jdbc/osclassDB' in SerialContext</em> </p>
  
  <p>This is what I did: I set up a <strong>JDBC Connection Pool</strong> and a <strong>JDBC Resource</strong> pointing to that pool (both in Glassfish). </p>
  
  <p>Then I told my <strong>web.xml</strong> that there is a JDBC Resource:</p>
  
  <pre><code>&lt;resource-ref&gt;
      &lt;res-ref-name&gt;jdbc/osclassDB&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
      &lt;res-sharing-scope&gt;Shareable&lt;/res-sharing-scope&gt;                
  &lt;/resource-ref&gt;
  </code></pre>
  
  <p>And then I tried using that resource in a <strong>Servlet:</strong> </p>
  
  <pre><code>  Connection connection = null;
  
    try {        
       InitialContext initialContext = new InitialContext();
       //Context dbContext = (Context) initialContext.lookup("java:comp/env");
  
       DataSource dataSource = (DataSource) initialContext.lookup("jdbc/osclassDB");
       connection = dataSource.getConnection();
  
       if (connection == null) {
           throw new SQLException("Error establishing connection!");
       }
       // some queries here
    } 
    // catch and finally close connection
  </code></pre>
  
  <p>But when I call the <code>Servlet</code> it throws me the <code>NamingException</code> and tells me that the <code>Lookup failed for 'jdbc/osclassDB' in SerialContext</code></p>
  
  <p><strong>What am I doing wrong here?</strong> is it the web.xml? did I miss something?
  Thank you for your help! </p>