title: why does the javax.naming.NamingException occur here?
body: <p>when i run the following :</p>
  
  <pre><code>package NonServletFiles;
  import java.sql.Connection;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import javax.sql.DataSource;
  import javax.naming.*;
  
  public class GetTagsFromDatabase {
  
  public GetTagsFromDatabase() {
  
  }
  
  public String[] getTags() {
  
      String tags[] = null;
      try {
          Context context = new InitialContext();
          DataSource ds = (DataSource)context.lookup("java:comp/env/jdbc/photog"); // &lt;&lt;----- line 23
          Connection connection = ds.getConnection();
          String sqlQuery = "select NAMEOFTHETAG from tagcollection";
          PreparedStatement statement = connection.prepareStatement(sqlQuery);
          ResultSet set = statement.executeQuery();
  
          int i = 0;
          while(set.next()) {
              tags[i] = set.getString("NameOfTheTag");
              System.out.println(tags[i]);
              i++;
          }
      }catch(Exception exc) {
          exc.printStackTrace();
      }
  
      return tags;
  }
  
  public static void main(String args[]) {
      new GetTagsFromDatabase().getTags(); // &lt;&lt;----- line 43
  }
  }
  </code></pre>
  
  <p>I get the following exceptions :</p>
  
  <pre><code>javax.naming.NamingException: Lookup failed for 'java:comp/env/jdbc/photog' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
  at javax.naming.InitialContext.lookup(InitialContext.java:411)
  at NonServletFiles.GetTagsFromDatabase.getTags(GetTagsFromDatabase.java:23)
  at NonServletFiles.GetTagsFromDatabase.main(GetTagsFromDatabase.java:43)
  
  Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation 
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getComponentId(GlassfishNamingManagerImpl.java:873)
  at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:742)
  at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:172)
  at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:498)
  ... 4 more
  </code></pre>
  
  <p>I don't know the reason for this exception,all other servlets that need to connect to the database with the url <code>java:comp/env/jdbc/photog</code> work fine.</p>