Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Tomcat DataSource problem

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
vaibhavmishra062201
Asked:
vaibhavmishra062201
1 Solution
 
vaibhavmishra062201Author Commented:
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
 
Computer101Commented:
PAQed, with points refunded (250)

Computer101
E-E Admin
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now