Solved

Tomcat DataSource problem

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unsearchable in Google,Yahoo and Bing. 6 58
IIS url rewrite rule for web application 3 52
wordpress email form 23 72
http to https 3 38
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

11 Experts available now in Live!

Get 1:1 Help Now