yoavs 2005/03/25 19:16:18
Modified: webapps/docs changelog.xml
jndi-datasource-examples-howto.xml
Log:
Bugzilla 33755.
Revision Changes Path
1.272 +4 -0 jakarta-tomcat-catalina/webapps/docs/changelog.xml
Index: changelog.xml
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/changelog.xml,v
retrieving revision 1.271
retrieving revision 1.272
diff -u -r1.271 -r1.272
--- changelog.xml 25 Mar 2005 22:24:20 -0000 1.271
+++ changelog.xml 26 Mar 2005 03:16:18 -0000 1.272
@@ -60,6 +60,10 @@
<add>
<bug>33325</bug>: Added top-level clean target to Netbuild build.xml
file. (yoavs)
</add>
+ <update>
+ <bug>33755</bug>: Clarified Postgresql JNDI datasource example.
[patch submitted by
+ Tom Witmer] (yoavs)
+ </update>
</changelog>
</subsection>
1.14 +84 -7
jakarta-tomcat-catalina/webapps/docs/jndi-datasource-examples-howto.xml
Index: jndi-datasource-examples-howto.xml
===================================================================
RCS file:
/home/cvs/jakarta-tomcat-catalina/webapps/docs/jndi-datasource-examples-howto.xml,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- jndi-datasource-examples-howto.xml 27 Sep 2004 16:00:31 -0000
1.13
+++ jndi-datasource-examples-howto.xml 26 Mar 2005 03:16:18 -0000
1.14
@@ -30,7 +30,7 @@
<section name="Introduction">
<p>JNDI Datasource configuration is covered extensively in the
-JNDI-Resources-HOWTO however, feedback from <code>tomcat-user</code> has
+JNDI-Resources-HOWTO. However, feedback from <code>tomcat-user</code> has
shown that specifics for individual configurations can be rather tricky.</p>
<p>Here then are some example configurations that have been posted to
@@ -41,6 +41,12 @@
know if you have any other tested configurations that you feel may be of use
to the wider audience, or if you feel we can improve this section in
anyway.</p>
+<p>
+<b>Please note that JNDI resource configuration has changed somewhat between
+Tomcat 5.0.x and Tomcat 5.5.x.</b> You will most likely need to modify your
JNDI
+resource configurations to match the syntax in the example below in order
+to make them work in Tomcat 5.5.x.
+</p>
</section>
<section name="Database Connection Pool (DBCP) Configurations">
@@ -335,16 +341,65 @@
<subsection name="PostgreSQL">
<h3>0. Introduction</h3>
-<p>PostgreSQL is configured in a similar manner to Oracle. Again,
highlighting the differences.
-These notes are untested as yet and we would appreciate feedback.</p>
-<h3>1. server.xml configuration</h3>
+<p>PostgreSQL is configured in a similar manner to Oracle.</p>
+
+<h3>1. Required files </h3>
+<p>
+Copy the Postgres JDBC jar to $CATALINA_HOME/common/lib. As with Oracle, the
+jars need to be in this directory in order for DBCP's Classloader to find
+them. This has to be done regardless of which configuration step you take
next.
+</p>
+
+<h3>2. Resource configuration</h3>
+
+<p>
+You have two choices here: define a datasource that is shared across all
Tomcat
+applications, or define a datasource specifically for one application.
+</p>
+
+<h4>2a. Shared resource configuration</h4>
+<p>
+Use this option if you wish to define a datasource that is shared across
+multiple Tomcat applications, or if you just prefer defining your datasource
+in this file.
+</p>
+<p><i>This author has not had success here, although others have reported so.
+Clarification would be appreciated here.</i></p>
+
<source>
<Resource name="jdbc/postgres" auth="Container"
type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://127.0.0.1:5432/mydb"
- username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
maxWait="-1"/>
+ username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
maxWait="-1"/>
</source>
-<h3>2. web.xml configuration</h3>
+<h4>2b. Application-specific resource configuration</h4>
+
+<p>
+Use this option if you wish to define a datasource specific to your
application,
+not visible to other Tomcat applications. This method is less invasive to
your
+Tomcat installation.
+</p>
+
+<p>
+Create a resource definition file for your application defining the
+datasource. This file must have the same name as your application, so if
+your application deploys as <code>someApp.war</code>, this filename must
+be <code>someApp.xml</code>. This file should look something like the
following.
+</p>
+
+<source>
+<Context path="/someApp" docBase="someApp"
+ crossContext="true" reloadable="true" debug="1">
+
+<Resource name="jdbc/postgres" auth="Container"
+ type="javax.sql.DataSource" driverClassName="org.postgresql.Driver"
+ url="jdbc:postgresql://127.0.0.1:5432/mydb"
+ username="myuser" password="mypasswd" maxActive="20" maxIdle="10"
+maxWait="-1"/>
+</Context>
+</source>
+
+<h3>3. web.xml configuration</h3>
<source>
<resource-ref>
<description>postgreSQL Datasource example</description>
@@ -353,10 +408,32 @@
<res-auth>Container</res-auth>
</resource-ref>
</source>
+
+<h4>4. Accessing the datasource</h4>
+<p>
+When accessing the datasource programmatically, remember to prepend
+<code>java:/comp/env</code> to your JNDI lookup, as in the following snippet
of
+code. Note also that "jdbc/postgres" can be replaced with any value you
prefer, provided
+you change it in the above resource definition file as well.
+</p>
+
+<source>
+InitialContext cxt = new InitialContext();
+if ( cxt == null ) {
+ throw new Exception("Uh oh -- no context!");
+}
+
+DataSource ds = (DataSource) cxt.lookup( "java:/comp/env/jdbc/postgres" );
+
+if ( cxt == null ) {
+ throw new Exception("Data source not found!");
+}
+</source>
+
</subsection>
</section>
-<section name="Non DBCP Solutions">
+<section name="Non-DBCP Solutions">
<p>
These solutions either utilise a single connection to the database (not
recommended for anything other
than testing!) or some other pooling technology.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]