?
Solved

Tomcat and JNDI Configuration

Posted on 2004-10-11
4
Medium Priority
?
261 Views
Last Modified: 2010-04-20
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">
            <parameter>
              <name>url</name>
              <value>jdbc:mysql://localhost:3306/sog</value>
            </parameter>
            <parameter>
              <name>password</name>
              <value>webuser</value>
            </parameter>
            <parameter>
              <name>maxActive</name>
              <value>40</value>
            </parameter>
            <parameter>
              <name>maxWait</name>
              <value>5000</value>
            </parameter>
            <parameter>
              <name>driverClassName</name>
              <value>org.gjt.mm.mysql.Driver</value>
            </parameter>
            <parameter>
              <name>user</name>
              <value>soguser</value>
            </parameter>
            <parameter>
              <name>maxIdle</name>
              <value>40</value>
            </parameter>
          </ResourceParams>
        </Context>

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"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  <description>MySQL Test App</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/SOGDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>


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 (rs.next())
                  {
                        out.println(rs.getString(2));
                  }

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.  
0
Comment
Question by:techhound
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12306447
Did u included the my SQL JDBC Driver in the Tomcat classpath?
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12306457
Also please print out the Error stack trace by

err..printStackTrace();
0
 

Author Comment

by:techhound
ID: 12306592
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?

Thanks
0
 
LVL 13

Accepted Solution

by:
petmagdy earned 2000 total points
ID: 12306830
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:

<%

try
{
 //your code
}
catch(Exception err)
{
  err.printStackTrace();
}

%>

this will display the error on the tomcat console or tomcat log file
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question