JNDI Setup in Embedded Tomcat 5.0.19

Hi All,
I have embedded Tomcat 5.0.19 in my application, which is a simple web based database application in servlets. In Embedded Tomcat we don't have server.xml.
Reference:
http://www.vsj.co.uk/articles/display.asp?id=319
I am trying to create JNDI Context to connect to my database.
My configuration file is like this:
<naming>
<context >
<resource name="jdbc/myDS" type="javax.sql.DataSource" >
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>net.sourceforge.jtds.jdbc.Driver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:jtds:sqlserver://SQLServer:1433;databaseName=myDB;</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value>sa</value>
</parameter>
</resource>
</context>
</naming>
I have put this config file in the root directory and called thru the following method.
XmlConfigurator.loadConfiguration(getClass().getResourceAsStream("/myConfig.xml"));
Ref:
http://directory.apache.org/subprojects/naming/using.html
I have written a class which starts the embedded tomcat and calls the above method.
The following is the output of tomcat:
Apr 15, 2005 3:19:00 PM org.apache.catalina.startup.Embedded start
INFO: Starting tomcat server
Apr 15, 2005 3:19:01 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.0.19
Apr 15, 2005 3:19:01 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Apr 15, 2005 3:19:01 PM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.util.LocalStrings', returnNull=tru
e
Apr 15, 2005 3:19:01 PM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='org.apache.struts.action.ActionResources', returnNul
l=true
Apr 15, 2005 3:19:02 PM org.apache.struts.util.PropertyMessageResources <init>
INFO: Initializing, config='view.ApplicationResources', returnNull=true
Apr 15, 2005 3:19:02 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on port 9889
Apr 15, 2005 3:19:02 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on port 9889
I have written another class which does the context lookup function and creates the Connection Object like this:
public Connection getConnection()
     Context ctx=new InitialContext();
Context jdbcCtx = (Context)ctx.lookup("jdbc");
DataSource datasource=(DataSource)jdbcCtx.lookup("myDS");
return datasource.getConnection();
but every time my web application calls this function to create a new connection it throws:
javax.naming.NameNotFoundException: Name jdbc is not bound in this Context
at org.apache.naming.NamingContext.lookup(NamingContext.java:815)
at org.apache.naming.NamingContext.lookup(NamingContext.java:198)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:183)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at view.DatabaseConnection.getConnection(DatabaseConnection.java:109)
at view.Admin_LoginValidation.doPost(Admin_LoginValidation.java:42)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:284)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:204)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:257)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
at org.apache.catalina.core.StandardContextValve.invokeInternal(Standard
ContextValve.java:245)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:199)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:184)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:164)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:149)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:156)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValv
eContext.java:151)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:567)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:972)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:20
6)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:833)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:732)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:619)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:688)
at java.lang.Thread.run(Thread.java:534)
java.lang.NullPointerException
when I tried Context lookup in the same class which starts Tomcat, there is no problem: it gets the Name jdbc/myDB. How to make the Context Global.
Please help me out to solve this problem.
Thanks in Advance,
Pretty

in the reource tag u have somet hing called global attribute which will be ur global jndi name with which u can access the resource
Context ...>
<ResourceLink name="The name of the linked global resource in the global JNDI context.
global="The name of the resource link to be created, relative to the java:comp/env context.
type="The fully qualified Java class name expected by the web application when it performs a lookup for this resource link.
r"
i think tat will work
regards
shanu
</Context>

Similar Messages

  • Embedded Tomcat 5.5 return 404 for all request

    I am starting embedded tomcat within a Java application, but it returns 404 when i request a existing static content html file. I have no idea why is that and there is no service using the port. Please advise.
    File structures are as follow:
    base directory: D:\AXIS
    directory with index.html - D:\AXIS\webapps\root\
    other existing dir
    D:\AXIS\webapps\root\WEB-INF\lib\
    D:\AXIS\webapps\root\WEB-INF\
    debug level is set to 5 and following is the response of log screen when i request http://localhost:7070/index.html :
    Command> HttpProcessor[7070][3] An incoming request is being assigned
    HttpProcessor[7070][3] The incoming request has been awaited
    HttpProcessor[7070][3] parseConnection: address=/127.0.0.1, port=7070
    HttpProcessor[7070][3] Normalized: '/index.html' to '/index.html'
    HttpProcessor[7070][3] Request is 'GET' for '/index.html' with protocol 'HTTP/1.1'
    HttpProcessor[7070][3] Header accept = */*
    HttpProcessor[7070][3] Header accept-language = en-us
    HttpProcessor[7070][3] Adding locale 'en_US'
    HttpProcessor[7070][3] Header accept-encoding = gzip, deflate
    HttpProcessor[7070][3] Header user-agent = Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    HttpProcessor[7070][3] Header host = localhost:7070
    HttpProcessor[7070][3] Header connection = Keep-Alive
    StandardEngine[null]: Mapping server name 'localhost'
    StandardEngine[null]: Trying a direct match
    StandardHost[localhost]: Mapping request URI '/index.html'
    StandardHost[localhost]: Trying the longest context path prefix
    StandardHost[localhost]: Mapped to context ''
    StandardContext[]: Mapping contextPath='' with requestURI='/index.html' and relativeURI='/index.html'
    StandardContext[]: Decoded relativeURI='/index.html'
    StandardContext[]: Trying exact match
    StandardContext[]: Trying prefix match
    StandardContext[]: Trying extension match
    StandardContext[]: Trying default match
    HttpProcessor[7070][3] parseConnection: address=/127.0.0.1, port=7070
    Following is server start code.
    public class EmbeddedTomcat {
    private String path = null;
    private Embedded embedded = null;
    private Host host = null;
    * Default Constructor
    public EmbeddedTomcat() {
    * Basic Accessor setting the value of the context path
    * @param path - the path
    public void setPath(String path) {
    this.path = path;
    * Basic Accessor returning the value of the context path
    * @return - the context path
    public String getPath() {
    return path;
    * This method Starts the Tomcat server.
    public void startTomcat() throws Exception {
    Engine engine = null;
    // Set the home directory
    System.setProperty("catalina.home", getPath());
    System.setProperty("catalina.base", getPath());
    // Create an embedded server
    embedded = new Embedded();
    // print all log statments to standard error
    embedded.setDebug(99);
    embedded.setLogger(new SystemOutLogger());
    // Create an engine
    engine = embedded.createEngine();
         engine.setDefaultHost("localhost");
    // Create a default virtual host
    host = embedded.createHost("localhost", getPath() + "/webapps");
         engine.addChild(host);
    // Create the ROOT context
    Context context = embedded.createContext("", getPath() + "/webapps/root");
         System.out.println("Doc Base - " + context.getDocBase());
         host.addChild(context);
    // Install the assembled container hierarchy
    embedded.addEngine(engine);
    // Assemble and install a default HTTP connector
    Connector connector = embedded.createConnector(null, 7070, false);
    embedded.addConnector(connector);
    // Start the embedded server
    embedded.start();
    public static void main(String args[]) {
    try {
    EmbeddedTomcat tomcat = new EmbeddedTomcat();
    tomcat.setPath("D:/AXIS");
         tomcat.startTomcat();
    catch( Exception e ) {
    e.printStackTrace();
    Thanks is advance,
    Jerry

    in the reource tag u have somet hing called global attribute which will be ur global jndi name with which u can access the resource
    Context ...>
    <ResourceLink name="The name of the linked global resource in the global JNDI context.
    global="The name of the resource link to be created, relative to the java:comp/env context.
    type="The fully qualified Java class name expected by the web application when it performs a lookup for this resource link.
    r"
    i think tat will work
    regards
    shanu
    </Context>

  • Problem with embedded tomcat...I think

    Hi,
    To be honest, I am not sure where the best place to post this question is, so I will try here, and then go from there. :)
    I have a website setup on the embedded tomcat webserver that comes with JSE8. I have then written a small app (very small) that uses the HttpURLConnection object to try and connect to a page on this website. Now, if I try and connect to the page via a normal browser, I have no problem, but if I try via the code, I get an 503, Server Unavailable error. I know that the website is working (as I can connect via a browser, as I said), so I am at a loss as to what is wrong. My code is:
                SocketAddress address = new InetSocketAddress("proxy.tfh-wildau.de", 8080);
                Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
                URL url = new URL("http://127.0.0.1:8084/test.html");
                HttpURLConnection hConn = (HttpURLConnection) url.openConnection(proxy);
                hConn.setDoInput(true);
                hConn.setDoOutput(true);
                hConn.connect();
                System.out.println(hConn.getResponseMessage());
                System.out.println(hConn.getResponseCode());If I change the web addres to, say, www.google.com, then there is no problem. Is the problem because I am trying to connect to a server on my own machine? Or is the problem because the server is part of the JSE IDE and too many threads are being created within the JVM...I dunno...I hope someone can shed some light on this, or at least point me towards the appropriate forum.
    Thanks in advance

    never mind...I realised that my internet setup was such that it was still trying to go through the proxy server for local address. Once I told it to bypass the proxy for local address, and removed the Proxy bit of the code, it works fine.

  • How to deploy war file in embedded Tomcat in UCM

    Hi ,
    Can anyone please share the steps to configure embedded Tomcat in UCM, And steps to deploy individual JSP and War file.
    thanks,
    Edited by: user4884609 on Feb 13, 2012 4:23 PM

    one more question :
    The Url to access war file is something like this :
    http://localhost/idc/groups/jsp/documents/webapps/testwar/test.jsp
    Can we have friendly URL for war file ? something like http://localhost/testwar/test.jsp or may be http://localhost/idc/testwar/test.jsp ?

  • How to refer to JNDI PROVIDER_URL from within Tomcat Web app

    Can anyone provide a clear description on how to refer to a "Provider_URL" relative to the web application root for which a Java Class resides within? My issue is as follows. I've looked through the JNDI tutorial and the Tomcat JNDI How-To's and I'm still unable to find a solution.
    I'll elaborate:
    I have a "PROVIDER_URL" class variable defined as:
    private String PROVIDER_URL = "file:/C:/development/MyProject/MyWebApplication/WEB-INF/properties";I initialize my JNDI context within the class:
    Properties properties = new Properties();
    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    properties.setProperty(Context.PROVIDER_URL, PROVIDER_URL);
    context = new InitialContext(properties);
    cpds = (ConnectionPoolDataSource) context.lookup(baseName);
    ...The above example works fine. My question is given my web app's directory, how do I refer to "MyWebApplication/WEB-INF/properties" in a relative manner so that if I move my web application to a different server, the directory path does not affect my deployment and I dont have to hardcode the current path? Does this need to occur in the "server.xml" file? Can you provide a URL to an example?
    Your suggestions are appreciated...thanks.

    try to give
    http://localhost:8080
    or the app server based port address.

  • How to make Visitor Tracking in embedded Tomcat.

    Hi, Please help me.
    I want to know how to make visitor tracking in embedded Tomcat. If you know, how to catch all the incoming clients to Tomcat, please tell me. I don't know how to catch them.

    enable logging on the server

  • Embedded Tomcat Java Application

    Hi
    I am using an Embedded Tomcat Java Application.
    I am getting the following Exception when i run the program.
    java.lang.NullPointerException
         at org.apache.catalina.startup.DigesterFactory.register(DigesterFactory.java:174)
         at org.apache.catalina.startup.DigesterFactory.registerLocalSchema(DigesterFactory.java:130)
         at org.apache.catalina.startup.DigesterFactory.newDigester(DigesterFactory.java:92)
         at org.apache.catalina.startup.ContextConfig.createWebXmlDigester(ContextConfig.java:435)
         at org.apache.catalina.startup.ContextConfig.createWebDigester(ContextConfig.java:422)
         at org.apache.catalina.startup.ContextConfig.defaultConfig(ContextConfig.java:499)
         at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:623)
         at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:216)
         at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
         at org.apache.catalina.core.StandardContext.start(StandardContext.java:4290)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
         at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
         at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
         at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
         at org.apache.catalina.startup.Embedded.start(Embedded.java:846)
         at EmbeddedTomcat.startTomcat(EmbeddedTomcat.java:77)
         at EmbeddedTomcat.main(EmbeddedTomcat.java:135)
    could anyone tell me how to solve this problem
    Thanx & Regards
    Faisal

    Hi
    R u able to resolve the problems.... If yes please provide me the info... I'm also facing the same problem...
    REgards
    siddhu

  • Configure the embedded Tomcat Server

    Hello,
    is there a documentation which tells me how to configure the embedded Tomcat Server in the Oracle Content Server? I can't get it work.
    When I try to start an web application from "JSP Server Web App Admin" I get the following error message:
    Content Server Request Failed
    csJspServerErrorAddWebAppService Failed to add context /idc/groups/jsp/documents/adacct/hello. Unable to execute service method 'addContext'.
    [ Details ]
    intradoc.common.ServiceException: !csJspServerErrorAddContext,/idc/groups/jsp/documents/adacct/hello!csUnableToExecMethod,addContext at intradoc.server.jsp.JspServiceHandler.addContext(JspServiceHandler.java:152) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at intradoc.common.IdcMethodHolder.invokeMethod(ClassHelperUtils.java:461) at intradoc.common.ClassHelperUtils.executeMethodReportStatus(ClassHelperUtils.java:142) at intradoc.server.ServiceHandler.executeAction(ServiceHandler.java:75) at intradoc.server.Service.doCodeEx(Service.java:488) at intradoc.server.Service.doCode(Service.java:470) at intradoc.server.ServiceRequestImplementor.doAction(ServiceRequestImplementor.java:1350) at intradoc.server.Service.doAction(Service.java:450) at intradoc.server.ServiceRequestImplementor.doActions(ServiceRequestImplementor.java:1191) at intradoc.server.Service.doActions(Service.java:445) at intradoc.server.ServiceRequestImplementor.executeActions(ServiceRequestImplementor.java:1111) at intradoc.server.Service.executeActions(Service.java:431) at intradoc.server.ServiceRequestImplementor.doRequest(ServiceRequestImplementor.java:632) at intradoc.server.Service.doRequest(Service.java:1709) at intradoc.server.ServiceManager.processCommand(ServiceManager.java:357) at intradoc.server.IdcServerThread.run(IdcServerThread.java:195) Caused by: intradoc.common.ServiceException: !csJspServerErrorAddContext,/idc/groups/jsp/documents/adacct/hello!csUnableToExecMethod,addContext at intradoc.server.jsp.JspProvider.addContext(JspProvider.java:391) at intradoc.server.jsp.JspServiceHandler.addContext(JspServiceHandler.java:116) ... 19 more
    And it is also not possible to use jsp layout pages in Site created in Site Studio. When I try to load pages using a jsp layout page the browser displays a blank page.

    Hi,
    Even i am also facing the same issue after following all those steps.
    Please find the error which i m getting.
    csJspServerErrorAddWebAppService The target file cannot be accessed. Unable to rename the file 'F:\stellent\indxpdod2\weblayout\groups\chanpart\@cccd\documents\manufacturing\enhstellsrchint' to 'F:\stellent\indxpdod2\weblayout\groups\chanpart\@cccd\documents\manufacturing\enhstellsrchint~jsp'.

  • Hello world servlet on UCM 11g embedded tomcat

    Hi,
    I'm using UCM 11.1.1.5. I'm trying to run a simple jsp and servlet (hello world) on UCM embedded Tomcat (deployed with a war).
    I successfully executes jsp, however I'm not able to runs servlets...I receive a 404 Http error (generated by WebLogic).
    Deploying the same war on a external standalone tomcat server I successfully run the servlet.
    Have you any idea?
    Any input will be greatly appreciated.
    Thanks for your helps,
    S.

    In order to be more complete, it follows the web.xml:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
    <display-name>Hello, World Application</display-name>
    <description>
    This is a simple web application with a source code organization
    based on the recommendations of the Application Developer's Guide.
    </description>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>mypackage.Hello</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    </web-app>
    Thank you very much.
    Best regards,
    S.

  • [svn:bz-4.0.0_fixes] 21088: Update readme. txt for tomcat authentication to include setup instructions for Tomcat 7.

    Revision: 21088
    Revision: 21088
    Author:   [email protected]
    Date:     2011-04-15 09:50:24 -0700 (Fri, 15 Apr 2011)
    Log Message:
    Update readme.txt for tomcat authentication to include setup instructions for Tomcat 7.
    checkintests: not run. not code change.
    Modified Paths:
        blazeds/branches/4.0.0_fixes/resources/security/tomcat/readme.txt

    Remember that Arch Arm is a different distribution, but we try to bend the rules and provide limited support for them.  This may or may not be unique to Arch Arm, so you might try asking on their forums as well.

  • How to find global JNDI listings from embeded OC4j

    I am having a hard time looking up the context of a local bean. Remote works fine for some reason.
    How do I get a listing of the global jndi namespace for embeded OC4J?

    Hi
    Though we never 'recommend' using olite for complex processes, as olite is only for simple testing/dev purpose.
    However, you can still apply the 10.1.3.4 patchset for this BPEL standalone installation, without installing SOA Suite. But, in future I would recommend Advanced SOA Suite with 10.2.0.3 DB.
    Hope that answers your questions!
    Cheers
    Anirudh Pucha

  • Problem with JNDI and JSP in Tomcat

    Hi,
    Basically, what I've done is to use the Tomcat administration web
    application to create the DataSource, which looks like it populated the
    server.xml (see below). I then try to access the testconn.jsp, and am
    getting that "Name java:comp is not bound in this Context" error.
    I was wondering if anyone could tell me what I'm doing wrong?
    Thanks,
    Feri
    My Configuration:
    - Tomcat 5.0.19
    - MySQL 4.0.18-nt
    - mysql-connector-java-3.0.15-ga-bin.jar
    server.xml:
    <GlobalNamingResources>
    <!-- Test entry for demonstration purposes -->
    <Environment name="simpleValue" type="java.lang.Integer" value="30"/>
    <!-- Editable user database that can also be used by
    UserDatabaseRealm to authenticate users -->
    <Resource name="UserDatabase" auth="Container"
    type="org.apache.catalina.UserDatabase"
    description="User database that can be updated and saved">
    </Resource>
    <ResourceParams name="UserDatabase">
    <parameter>
    <name>factory</name>
    <value>org.apache.catalina.users.MemoryUserDatabaseFactory</value>
    </parameter>
    <parameter>
    <name>pathname</name>
    <value>conf/tomcat-users.xml</value>
    </parameter>
    </ResourceParams>
    <!--Feri test JNDI-->
         <Context crossContext="true" debug="5" docBase="injury" path="/injury" reloadable="true">
         <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_injury_log." suffix=".txt" timestamp="true"/>
              <Resource name="jdbc/injury" auth="Container"
    type="javax.sql.DataSource">
    </Resource>
    <ResourceParams name="jdbc/injury">
         <parameter>
              <name>factory</name>
              <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
         </parameter>
    <parameter>
    <name>username</name>
    <value>root</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>root</value>
    </parameter>
         <parameter>
    <name>driverClassName</name>
    <value>com.mysql.jdbc.Driver</value>
    </parameter>
         <parameter>
    <name>url</name>
    <value>jdbc:mysql://localhost:3306/injury</value>
    </parameter>
         <parameter>
              <name>maxIdle</name>
              <value>30</value>
         </parameter>
         <parameter>
              <name>maxActive</name>
              <value>10</value>
         </parameter>
         <parameter>
              <name>maxWait</name>
              <value>10000</value>
         </parameter>
    </ResourceParams>
         </Context>
    <!--Feri test JNDI end-->
    </GlobalNamingResources>
    \webapps\injury\WEB-INF\web.xml:
    <resource-ref>
    <description>Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file.</description>
    <res-ref-name>jdbc/injury</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    \webapps\injury\testconn.jsp
    <%@ page import="java.sql.*" %>
    <%@ page import="javax.sql.*" %>
    <%@ taglib prefix="ct" uri="/injury" %>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
    <h1>Connection test</h1>
    <ct:connection name="jdbc/injury">
    <%
    Statement stmt= conn.createStatement();
    ResultSet rs;
    rs = stmt.executeQuery("select * from user");
    while (rs.next()){
    %><%=rs.getString(1)%><%=rs.getInt(2) %><br><%
    rs.close();
    stmt.close();
    %>
    </ct:connection>
    ConnectionTag.java
    import java.io.*;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    import javax.naming.*;
    import javax.sql.*;
    import javax.sql.DataSource;
    public class ConnectionTag extends TagSupport implements TryCatchFinally {
    private Connection conn;
    // JNDI name of the connection
    private String name;
    public void setName(String name)
         this.name = name;
    public int doStartTag()
         throws JspException
         try {
         Context env = (Context) new InitialContext().lookup("java:comp/env");
         DataSource ds = (DataSource) env.lookup(name);
         if (ds != null)
              conn = ds.getConnection();
         } catch (Exception e) {
         throw new JspException(e);
         if (conn == null)
         throw new JspException("can't open connection " + name);
         pageContext.setAttribute("conn", conn);
         return EVAL_BODY_INCLUDE;
    public void doCatch(Throwable t)
         throws Throwable
         throw t;
    public void doFinally()
         try {
         Connection conn = this.conn;
         this.conn = null;
         pageContext.removeAttribute("conn");
         conn.close();
         } catch (Exception e) {
    Tomcat 5.0\conf\Catalina\localhost\injury.xml
    <?xml version='1.0' encoding='utf-8'?>
    <Context displayName="Injury" docBase="E:\Tomcat 5.0\webapps\injury" path="/injury" className="org.apache.catalina.core.StandardContext"
    cachingAllowed="true" charsetMapperClass="org.apache.catalina .util.CharsetMapper" cookies="true" crossContext="false" debug="0"
    mapperClass="org.apache.catalina.core.StandardContextMapper" useNaming="true" wrapperClass="org.apache.catalina.core.StandardWrapper" >
    <Resource auth="Container" description="Resource reference to a factory for java.sql.Connection instances that may be used for talking to a particular database that is configured in the server.xml file." name="jdbc/injury" type="javax.sql.DataSource"/>
    <ResourceLink global="jdbc/injury" name="injury" type="javax.sql.DataSource"/>
    </Context>

    Hi,
    First of all, you can find alot of information about this in the forum about jsp's.
    I think a good thing to do is not to put your context tag directly into the server.xml file.
    What you should do is create a context.xml file with the context-tag in it, and put it in the META-INF directory of your .war file. Upon deployment to tomcat5 this file will be extracted from the war, copied to the conf\enginename\hostname directory, and it will be renamed to contextName.xml.
    I think you are developing directly into the webapps directory, and I believe you should avoid that and use the deployment feature of the manager web-app or you should use the deployertool from you ide or standalone ant.
    anyway, for starters try to remove the context tag from the server.xml file as described above, and check out the jsp / jdbc forums for simular problems and answers.
    good luck

  • JNDI, Data Source and Tomcat

    Hi,
    I am using Tomcat 4.1
    I am using JDBC to connect to to SQL 2000.
    In the past I use JDBC 2.0 standsrd package to connect to it and it was fine.
    Now, for some reason, I need to use DataSource via JNDI.
    Here is my server.xml
    <Resource name="jdbc/SQLNorthwind" scope="Shareable" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/SQLNorthwind">
    <parameter>
    <name>validationQuery</name>
    <value>select * from Products</value>
    </parameter>
    <parameter>
    <name>url</name> <value>jdbc:microsoft:sqlserver://W2KSERVER1:1433;DatabaseName=Northwind</value>
    </parameter>
    <parameter>
    <name>password</name>
    <value>george</value>
    </parameter>
    <parameter>
    <name>maxActive</name>
    <value>20</value>
    </parameter>
    <parameter>
    <name>maxWait</name>
    <value>5000</value>
    </parameter>
    <parameter>
    <name>driverClassName</name>
    <value>com.microsoft.jdbcx.sqlserver.SQLServerDataSource</value>
    </parameter>
    <parameter>
    <name>username</name>
    <value>george</value>
    </parameter>
    <parameter>
    <name>maxIdle</name>
    <value>2</value>
    </parameter>
    </ResourceParams>
    It was generated by the Tomcat admin tools via the web browser.
    It is my web.xml
    <servlet>
    <servlet-name>JNDIDatabase</servlet-name>
    <display-name>JNDIDatabase</display-name>
    <description>JNDIDatabase</description>
    <servlet-class>com.testing.servlet.jdbc.jndi.JNDIDatabase</servlet-class>
    </servlet>
    Now here is my servlet source code for connection testing
    private Connection conn;
    private Statement stmt;
    private ResultSet rs;
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    try {
    Context ctx = new InitialContext();
    DataSource ds = (DataSource) ctx.lookup("jdbc/SQLNorthwind");
    conn = ds.getConnection("george", "george");
    } catch(NamingException e) {
    this.log("Naming exception in JNDIDatabase init", e);
    e.printStackTrace();
    } catch(SQLException e) {
    this.log("SQL exception in JNDIDatabase init", e);
    e.printStackTrace();
    The problem is no connection is obtained in init(). So what's wrong with my setting/code? Please help me to fix my setting/code.
    Thank you in advance.

    Follow what you said, no more NamingException. Thanks, Dave.
    now I receive another error.....
    2002-10-18 00:34:12 JNDIDatabase: SQL exception in JNDIDatabase init
    java.sql.SQLException: Cannot load JDBC driver class 'com.microsoft.jdbcx.sqlserver.SQLServerDataSource'
         at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:529)
         at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:329)
         at hk.com.scope.servlet.jdbc.jndi.JNDIDatabase.init(JNDIDatabase.java:37)
         at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:924)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:658)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2388)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
         at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
         at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
         at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:380)
         at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:533)
         at java.lang.Thread.run(Thread.java:536)
    I am sure msutil.jar, mssqlserver.jar and msbase.jar are stored in /WEB-INF/lib directory and using them in standard JDBC is OK!
    This is an extraction from MS JDBC help file.....
    The data source class for the SQL Server driver is:
    com.microsoft.jdbcx.sqlserver.SQLServerDataSource
    For information on SQL Server 2000 Driver for JDBC data sources, see "Connecting Through Data Sources".
    The driver class for the SQL Server driver is:
    com.microsoft.jdbc.sqlserver.SQLServerDriver
    com.microsoft.jdbc.sqlserver.SQLServerDriver is working properly, I am sure.

  • Embedding tomcat to run as a webserver

    Hi,
    I have compiled the Embedded.java source code to work in my environment.
    But the code includes the Thread.sleep , without that the code will terminate.
    So the webserver is running only for the time x,
    Thread.sleep(x)
    The sample code is:
    public static void main(String args[]) {
    try {
    EmbeddedTomcat tomcat = new EmbeddedTomcat();
         tomcat.setPath("d:/jakarta-tomcat-4.0.1");
    tomcat.startTomcat();
    Thread.sleep(1000000);
    tomcat.stopTomcat();
    how to avoid the thread.sleep so that the webserver is running continuously until it is shutdown explicitly
    Thanks

    Try running the tomcat service (embedded.start()) in a separate thread. I got the Embedded.java example working in this fashion by extending Thread and moving the code in the startTomcat() method to the public void run() method. To start the service, just call this.start(). Hope this helps...

  • JNDI setup

    Hi,
    How can I setup the jndi tree in oc4j?
    I'd like to store properties like the "SysAdminEmailAddress" in the JNDI.
    These properties should be accessible from all applications.
    In pre J2EE days we used a properties file loaded into the System.properties at startup.
    But now we think JNDI is the way to store it.
    In which config file can I store my properties?
    Thanks
    Guenther

    Dear OC4J Team,
    can you please give me a response.
    Many thanks
    Guenther

Maybe you are looking for

  • Runtime error in sales order creation

    Hai,When I am trying to create sales order one run time error is occured.The error is CALL_TRANSACTION_NOT_FOUND  TRANSACTION "%_GS" IS UNKNOWN.TRANSACTION "%_GS" IS NOT LISTED IN TABLE OF T.CODES.CURRENT ABAP PROGRAMME HAD TO BE TERMINATED BECAUSE O

  • Audition 5.1 audio can´t play correctely in Premiere ( 5.5 versions)

    Audition marvelously panning my audio in post of a film in 5.1. All aldio I made was very very good panned in audition . My computer is conected in a Sony AV with 7.1 capability of audio. The sound card´s outputs, ( FL, FR, C, LFE(SW) , RL, RR ) , WA

  • Mapping with changed message structure

    Hello, I have dowloaded a SAP IDOC into XI and build a mapping based on this IDOC. Now the IDOC is enhanced with a new (Z)segment and I have dowloaded the new structure again. But the new segment is not visible in the mapping based on that IDOC. Do I

  • Lost purchased songs

    Today when I was syncing my iPod and downloading the new software on my iPod touch 2nd generation. I looked at my music on it, I had lost all of the music that I had bought on my iPod. What do I do to get it back. It was a lot and I want those songs

  • Incoming mail error in window XP

    Hi, I have an issue in outlook 2007 or 2010 in windows XP machines. Receiving' reported error (0x800CCC1A) : 'Your server does not support the connection encryption type you have specified. Try changing the encryption method. Contact your mail server