Solved

Tomcat DataSource problem

Posted on 2004-08-13
3
404 Views
Last Modified: 2010-04-20
Hi

I am using Apache Tomcat 5.0.24
and trying to implement connection pooling

Successfully created data source through admin interface -
Tomcat Server->Service(Catalina)->Host(localhost)->Context(/NBA)->Resources->Data Sources

This is $CATALINA_HOME$\conf\Catalina\localhost\NBA.xml file after this
+++++++++++++++++++++++++++
<i>
<?xml version='1.0' encoding='utf-8'?>
<Context debug="5" displayName="NBA Server" docBase="NBA" path="/NBA" workDir="work\Catalina\localhost\NBA">
  <Resource name="jdbc/NBA" type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/NBA">
    <parameter>
      <name>maxWait</name>
      <value>5000</value>
    </parameter>
    <parameter>
      <name>maxActive</name>
      <value>4</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value>sa</value>
    </parameter>
    <parameter>
      <name>url</name>
      <value>jdbc:microsoft:sqlserver://192.168.3.137:1433;DatabaseName=NBA</value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    </parameter>
    <parameter>
      <name>maxIdle</name>
      <value>2</value>
    </parameter>
    <parameter>
      <name>username</name>
      <value>sa</value>
    </parameter>
  </ResourceParams>
</Context>
</i>
+++++++++++++++++++++++++++++++
This is my web.xml, i have added <resource-ref> tag
++++++++++++++++++++++++++++++
<i>
<?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>NBA</description>
    <display-name>NBA Server</display-name>
   
      <resource-ref>
        <description>NBA Database</description>
        <res-ref-name>jdbc/NBA</res-ref-name>
        <res-ref-type>javax.sql.DataSource</res-ref-type>
        <res-auth>Container</res-auth>
      </resource-ref>

      <servlet>
        <servlet-name>RouterServlet</servlet-name>
        <servlet-class>com.thq.nbap.servlets.RouterServlet</servlet-class>
       
            <init-param>
                  <param-name>webapp-name</param-name>
                  <param-value>NBA Server</param-value>
            </init-param>
            <init-param>
                  <param-name>cost</param-name>
                  <param-value>75</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
    </servlet>
   
    <servlet-mapping>
        <servlet-name>RouterServlet</servlet-name>
        <url-pattern>/router</url-pattern>
    </servlet-mapping>
</web-app>
</i>
++++++++++++++++++++++++++
And this is how I am trying to create connection in my database handling class
++++++++++++++++++++++++++
<i>
Context ctx=new InitialContext();
ds=(DataSource)ctx.lookup("jdbc/NBA");
</i>
++++++++++++++++++++++++++
This is giving me following exception -

javax.servlet.ServletException: Name jdbc is not bound in this Context
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:58)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


root cause

javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
      org.apache.naming.NamingContext.lookup(NamingContext.java:768)
      org.apache.naming.NamingContext.lookup(NamingContext.java:151)
      org.apache.naming.SelectorContext.lookup(SelectorContext.java:136)
      javax.naming.InitialContext.lookup(InitialContext.java:347)
      com.thq.nbap.db.DBConnectionManager.<init>(DBConnectionManager.java:31)
      org.apache.jsp.index_jsp._jspService(index_jsp.java:47)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:298)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:810)


I dont know what I have missed ?
Please help

vaibhav
0
Comment
Question by:vaibhavmishra062201
[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 Comments
 

Author Comment

by:vaibhavmishra062201
ID: 11791046
Somehow it is solved by me :)))

I changed the following code
+++++++++++++++++
Context ctx=new InitialContext();
ds=(DataSource)ctx.lookup("jdbc/NBA");
+++++++++++++++++
to this code
+++++++++++++++++
Context ctx=new InitialContext();
Context envContext=ctx.lookup("java:comp/env");
ds=(DataSource)envContext.lookup("jdbc/NBA");
+++++++++++++++++

hey i should get those points back ..!
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12318783
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
What You Need to Know when Searching for a Webhost Provider
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

623 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