Tomcat and JNDI Configuration

I configured my MySQL database to have the following:

<Context className="org.apache.catalina.core.StandardContext" cachingAllowed="true" charsetMapperClass="org.apache.catalina.util.CharsetMapper" cookies="true" crossContext="false" debug="0" docBase="c:\Tomcat\webapps\SOG" mapperClass="org.apache.catalina.core.StandardContextMapper" path="/SOG" privileged="false" reloadable="true" swallowOutput="false" useNaming="false" wrapperClass="org.apache.catalina.core.StandardWrapper">
          <Resource name="jdbc/SOGDB" auth="Container" scope="Shareable" type="javax.sql.DataSource"/>
          <ResourceParams name="jdbc/SOGDB">

Here is my web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
  <description>MySQL Test App</description>
      <description>DB Connection</description>

Then I try it with the following code:
                  Context ctx = new InitialContext();
                  if(ctx == null ) throw new Exception("Boom - No Context");
                        DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/SOGDB");
                  Connection conn = ds.getConnection();
                  Statement stmt = conn.createStatement();
                  ResultSet rs = stmt.executeQuery("select * from membership");
                  while (

I get an error:

Name java:comp not bound in this context.  I've successfully set up Microsoft SQL Server 2000 drivers in JNDI using the same methodology.  
James CochraneB2B FINTECH WRITER/Technology WriterAsked:
Who is Participating?
petmagdyConnect With a Mentor Commented:
The MySQL driver lock like this (mm.mysql-2.0.7-bin.jar) right?

in your jsp do this to get the print stack trace:


 //your code
catch(Exception err)


this will display the error on the tomcat console or tomcat log file
Did u included the my SQL JDBC Driver in the Tomcat classpath?
Also please print out the Error stack trace by

James CochraneB2B FINTECH WRITER/Technology WriterAuthor Commented:
The JDBC driver for MySQL is in the %TOMCAT_HOME%\common\lib directory.  I ran the above code using a jsp page.  Therefore, wouldn't it find the appropriate drivers from the directory?  The stack trace that I get is in the browser itself and only points to the compiled jsp page catch area.  I can still print the stack trace if you think that will help but where would I put then in the jsp page?  Should I set up a try/catch there and print it in the catch?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.