commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject cvs commit: jakarta-commons/dbcp/xdocs/guide jndi-howto.xml
Date Wed, 16 Jun 2004 18:29:20 GMT
dirkv       2004/06/16 11:29:20

  Added:       dbcp/xdocs/guide jndi-howto.xml
  instructions howto setup DBCP datasource inside a custom JNDI tree
  Revision  Changes    Path
  1.1                  jakarta-commons/dbcp/xdocs/guide/jndi-howto.xml
  Index: jndi-howto.xml
  <?xml version="1.0" encoding="ISO-8859-1"?>
     Copyright 2002-2004 The Apache Software Foundation
     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
    <title>Developers Guide</title>
    <author email="">Commons Documentation Team</author>
  <section name="JNDI Howto">
    The <a href="">Java Naming and Directory Interface</a>

    (JNDI) is part of the Java platform, 
    providing applications based on Java technology with a unified interface to 
    multiple naming and directory services. You can build powerful and portable 
    directory-enabled applications using this industry standard.
    When you deploy your application inside an application server, the container will setup
    the JNDI tree for you. But if you are writing a framework or just a standalone application,
    then the following examples will show you how to construct and bind references to DBCP

    Another source of information is 
    <a href="">Naming</a>.
    Naming includes an in-memory JNDI service provider that was extracted from the 
    <a href="">Jakarta Tomcat</a> JNDI implementation.
    It also contains a easy way to construct a JNDI tree from an XML file and some ResourceFactories.
    The following examples are using the sun filesystem JNDI service provider.
    You can download it from the 
    <a href="">JNDI software download</a>
    You can of course use the apache JNDI service provider by downloading the Naming core
    The initial context factory property should be changed to:
  <section name="BasicDataSource">
    System.setProperty(Context.PROVIDER_URL, "file:///tmp");
    InitialContext ic = new InitialContext();
    // Construct BasicDataSource reference
    Reference ref = new Reference("javax.sql.DataSource",
      "org.apache.commons.dbcp.BasicDataSourceFactory", null);
    ref.add(new StringRefAddr("driverClassName", "org.apache.commons.dbcp.TesterDriver"));
    ref.add(new StringRefAddr("url", "jdbc:apache:commons:testdriver"));
    ref.add(new StringRefAddr("username", "username"));
    ref.add(new StringRefAddr("password", "password"));
    ic.rebind("jdbc/basic", ref);
    // Use
    InitialContext ic2 = new InitialContext();
    DataSource ds = (DataSource) ic2.lookup("jdbc/basic");
    Connection conn = ds.getConnection();
  <section name="PerUserPoolDataSource">
    System.setProperty(Context.PROVIDER_URL, "file:///tmp");
    InitialContext ic = new InitialContext();
    // Construct DriverAdapterCPDS reference
    Reference cpdsRef = new Reference("org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS",
      "org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS", null);
    cpdsRef.add(new StringRefAddr("driver", "org.apache.commons.dbcp.TesterDriver"));
    cpdsRef.add(new StringRefAddr("url", "jdbc:apache:commons:testdriver"));
    cpdsRef.add(new StringRefAddr("user", "foo"));
    cpdsRef.add(new StringRefAddr("password", "bar"));
    ic.rebind("jdbc/cpds", cpdsRef);
    // Construct PerUserPoolDataSource reference
    Reference ref = new Reference("org.apache.commons.dbcp.datasources.PerUserPoolDataSource",
      "org.apache.commons.dbcp.datasources.PerUserPoolDataSourceFactory", null);
    ref.add(new StringRefAddr("dataSourceName", "jdbc/cpds"));
    ref.add(new StringRefAddr("defaultMaxActive", "100"));
    ref.add(new StringRefAddr("defaultMaxIdle", "30"));
    ref.add(new StringRefAddr("defaultMaxWait", "10000"));
    ic.rebind("jdbc/peruser", ref);
    // Use
    InitialContext ic2 = new InitialContext();
    DataSource ds = (DataSource) ic2.lookup("jdbc/peruser");
    Connection conn = ds.getConnection("foo","bar");

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message