In addition to defining the DataSource in Tomcat's admin tool, you'll need to define the Resource in you web.xml - something like this:

   <resource-ref>
       <!-- optional -->
       <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>
       <!-- local JNDI name to use in JSPs, servlets, etc. -->
       <res-ref-name>
           jdbc/phone
       </res-ref-name>
       <res-type>
           javax.sql.DataSource
       </res-type>
       <res-auth>
           Container
       </res-auth>
   </resource-ref>

You'll also need to define a ResourceLink in your Context, that links what you want to call your DataSource locally (used in web.xml, see above) to what you called your DataSource in the admin tool (globally ... these can be the same, but don't have to be). Something like this:

<ResourceLink global="jdbc/phone" name="jdbc/phone" type="javax.sql.DataSource"/>

The 'global' attribute provides the name of the global JNDI resource (what was defined in the admin tool); 'name' provides the name of the local JNDI resource (what will be referenced in web.xml).

That's it! You shouldn't have any problems once you've done this.

Respectfully,
Brice Ruth



Bussie, Andre D wrote:

I'm using Tomcat 5.0.19. I configured a datasource via the Tomcat Admin
tool to configure a datatsource listed below is the server.xml file
settings for the datasource

<GlobalNamingResources>

   <Resource name="jdbc/phone" auth="Container"
type="javax.sql.DataSource" description="Database for the phone
application" />

   <ResourceParams name="jdbc/phone">

           <parameter>

           <name>maxWait</name>

           <value>5000</value>

           </parameter>

           <parameter>

           <name>maxActive</name>

           <value>4</value>

           </parameter>

           <parameter>

           <name>password</name>

           <value></value>

           </parameter>

           <parameter>

           <name>url</name>

           <value>jdbc:hsqldb.hsql://localhost</value>

           </parameter>

           <parameter>

           <name>driverClassName</name>

           <value>org.hsqldb.jdbcDriver</value>

           </parameter>

           <parameter>

           <name>maxIdle</name>

           <value>2</value>

           </parameter>

           <parameter>

           <name>username</name>

           <value>sa</value>

           </parameter>

   </ResourceParams>

 </GlobalNamingResources>



However when I try to access the datasource from a jsp file I get the
following error

2004-07-26 10:42:19 StandardWrapperValve[jsp]: Servlet.service() for
servlet jsp threw exception

javax.naming.NameNotFoundException: Name jdbc/phone is not bound in this
Context



Code snippet listed below

<% InitialContext ctx = new InitialContext();

     DataSource ds =
(DataSource)ctx.lookup("java:comp/env/jdbc/phone");

     Connection conn = ds.getConnection();

     try{



Any suggestions on what can be causing this error. Why isn't in the
context and how do I bind it to the context?









-- Brice Ruth, Sr. IT Analyst Fiskars Brands Inc http://www.fiskarsbrands.com/


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to