tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jens K├╝hnberger <Kuehnber...@web.de>
Subject Re: [Solution] JNDI Data Source
Date Thu, 17 Oct 2002 18:58:38 GMT
Hi,

for those who followed this thread I just wanted to post the solution 
that worked for me.

In my server.xml I configured my context the following way:

<Context path="/axis" docBase="axis" debug="0">

   <Resource name="jdbc/auctionDB" auth="Container"
     type="javax.sql.DataSource"/>
   <ResourceParams name="jdbc/auctionDB">
     <parameter>
       <name>factory</name>
       <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
     </parameter>
     <parameter>
       <name>username</name>
       <value>yourUsername</value>
     </parameter>
     <parameter>
       <name>password</name>
       <value>yourPassword</value>
     </parameter>
     <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value></parameter>
     <parameter>
       <name>url</name>
 
<value>jdbc:mysql://localhost:3306/timeslotauction?autoReconnect=true</value>
     </parameter>
   </ResourceParams>

</Context>

In my 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/auctionDB
   </res-ref-name>
   <res-type>
     javax.sql.DataSource
   </res-type>
   <res-auth>
     Container
   </res-auth>
</resource-ref>

And then on the webpage:

  Context initCtx = new InitialContext();
  Context envCtx = (Context) initCtx.lookup("java:comp/env");
  DataSource ds = (DataSource)envCtx.lookup("jdbc/auctionDB");

OR

  Context initCtx = new InitialContext();
  DataSource ds = 
(DataSource)initCtx.lookup("java:comp/env/jdbc/auctionDB");

Thanks for the help

Jens


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message