Solved

Tomcat DataSource problem

Posted on 2004-08-13
3
389 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
3 Comments
 

Author Comment

by:vaibhavmishra062201
Comment Utility
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
Comment Utility
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

772 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now