Solved

Tomcat DataSource problem

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat7  URL keeps resolving to https instead of HTTP 4 67
Coldfusion Datefield problem 2 122
Website URL redirection 10 75
WEB Farm 6 76
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…
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 …

828 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