cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml
remm2002/09/24 05:12:22 Modified:webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: - Fix incorrect XML. - Submitted by matt at raibledesigns.com Revision ChangesPath 1.6 +1 -1 jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml Index: jndi-datasource-examples-howto.xml === RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- jndi-datasource-examples-howto.xml30 Aug 2002 13:41:25 - 1.5 +++ jndi-datasource-examples-howto.xml24 Sep 2002 12:12:22 - 1.6 @@ -613,7 +613,7 @@ lt;ResourceParams name=my-datasourcegt; lt;parametergt; lt;namegt;namelt;/namegt; -lt;valuegt;myDataSourcelt;/namegt; +lt;valuegt;myDataSourcelt;/valuegt; lt;/parametergt; lt;/ResourceParamsgt; /source -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml
glenn 2002/08/30 06:41:25 Modified:webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: Add FAQ for Random Closed Connection Exceptions Revision ChangesPath 1.5 +67 -0 jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml Index: jndi-datasource-examples-howto.xml === RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- jndi-datasource-examples-howto.xml18 Aug 2002 00:55:25 - 1.4 +++ jndi-datasource-examples-howto.xml30 Aug 2002 13:41:25 - 1.5 @@ -749,6 +749,73 @@ /subsection +subsection name=Random Connection Closed Exceptions +p +These can occur when one request gets a db connection from the connection +pool and closes it twice. When using a connection pool, closing the +connection just returns it to the pool for reuse by another request, +it doesn't close the connection. And Tomcat uses multiple threads to +handle concurrent requests. Here is an example of the sequence +of events which could cause this error in Tomcat: +pre + Request 1 running in Thread 1 gets a db connection. + + Request 1 closes the db connection. + + The JVM switches the running thread to Thread 2 + + Request 2 running in Thread 2 gets a db connection + (the same db connection just closed by Request 1). + + The JVM switches the running thread back to Thread 1 + + Request 1 closes the db connection a second time in a finally block. + + The JVM switches the running thread back to Thread 2 + + Request 2 Thread 2 tries to use the db connection but fails + because Request 1 closed it. +/pre +Here is an example of properly written code to use a db connection +obtained from a connection pool: +pre + Connection conn = null; + Statement stmt = null; // Or PreparedStatement if needed + ResultSet rs = null; + try { +conn = ... get connection from connection pool ... +stmt = conn.createStatement(select ...); +rs = stmt.executeQuery(); +... iterate through the result set ... +rs.close(); +rs = null; +stmt.close(); +stmt = null; +conn.close(); // Return to connection pool +conn = null; // Make sure we don't close it twice + } catch (SQLException e) { +... deal with errors ... + } finally { +// Always make sure result sets and statements are closed, +// and the connection is returned to the pool +if (rs != null) { + try { rs.close(); } catch (SQLException e) { ; } + rs = null; +} +if (stmt != null) { + try { stmt.close(); } catch (SQLException e) { ; } + stmt = null; +} +if (conn != null) { + try { conn.close(); } catch (SQLException e) { ; } + conn = null; +} + } +/pre +/p + +/subsection + /section /body -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml
[EMAIL PROTECTED] wrote: glenn 2002/08/30 06:41:25 Modified:webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: Add FAQ for Random Closed Connection Exceptions It seems I missed that update (unfortunaltely, I had to do the packaging now, or next monday). Anyway, it is likely we'll have a few issues to fix in 4.1.10 which would make it necessary to release another milestone. Remy -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
Re: cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml
Thats ok. Remy Maucherat wrote: [EMAIL PROTECTED] wrote: glenn 2002/08/30 06:41:25 Modified:webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: Add FAQ for Random Closed Connection Exceptions It seems I missed that update (unfortunaltely, I had to do the packaging now, or next monday). Anyway, it is likely we'll have a few issues to fix in 4.1.10 which would make it necessary to release another milestone. Remy -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED] -- -- Glenn Nielsen [EMAIL PROTECTED] | /* Spelin donut madder| MOREnet System Programming | * if iz ina coment. | Missouri Research and Education Network | */ | -- -- To unsubscribe, e-mail: mailto:[EMAIL PROTECTED] For additional commands, e-mail: mailto:[EMAIL PROTECTED]
cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml
glenn 2002/08/17 17:55:25 Modified:webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: Update docs for DBCP 1.0 release, cleanup, and add more info Revision ChangesPath 1.4 +312 -150 jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml Index: jndi-datasource-examples-howto.xml === RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- jndi-datasource-examples-howto.xml5 Jul 2002 13:17:46 - 1.3 +++ jndi-datasource-examples-howto.xml18 Aug 2002 00:55:25 - 1.4 @@ -9,66 +9,162 @@ properties author email=[EMAIL PROTECTED]Les Hughes/author author email=[EMAIL PROTECTED]David Haraburda/author -titleJNDI Datasource Examples HOW-TO/title +authorGlenn Nielsen/author +titleJNDI Datasource HOW-TO/title /properties body +section name=Table of Contents +p +a href=#IntroductionIntroduction/abr / +a href=#Database Connection Pool (DBCP) Configurations +Database Connection Pool (DBCP) Configurations/abr / +a href=#Tyrex Connection PoolTyrex Connection Pool/abr / +a href=#Non DBCP SolutionsNon DBCP Solutions/abr / +a href=#Oracle 8i with OCI clientOracle 8i with OCI client/abr / +a href=#Common ProblemsCommon Problems/abr / +/p +/section section name=Introduction -pJNDI Datasource configuration is covered extensively in the JNDI-Resources-HOWTO -however, feedback from codetomcat-user/code has shown that specifics for individual -configurations can be rather tricky./p -pHere then are some example configurations that have posted to tomcat-user -for popular databases./p +pJNDI Datasource configuration is covered extensively in the +JNDI-Resources-HOWTO however, feedback from codetomcat-user/code has +shown that specifics for individual configurations can be rather tricky./p + +pHere then are some example configurations that have been posted to +tomcat-user for popular databases and some general tips for db useage./p + +pYou should be aware that since these notes are derived from configuration +and/or feedback posted to codetomcat-user/code YMMV :-). Please let us +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 + /section -section name=Jakarta DBCP Pooled Configurations -pFor each of these configurations you will need the following Jakarta Commons projects -Note that currently, these all employ connection pooling -via the Jakarta-commons connection pool. Also, you should be aware that since these -notes are derived from the mysql configuration and/or feedback from codetomcat-user/code. -YMMV :-). Please let us 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 + +section name=Database Connection Pool (DBCP) Configurations + +pDBCP provides support for JDBC 2.0. On systems using a 1.4 JVM DBCP +will support JDBC 3.0. Please let us know if you have used DBCP and its +JDBC 3.0 features with a 1.4 JVM. +/p + +pSee the a href=http://jakarta.apache.org/commons/dbcp/api/index.html; +DBCP Javadocs/a BasicDataSource class for a complete list +of configuration parameters. +/p + +subsection name=Installation +pDBCP uses the Jakarta-Commons Database Connection Pool. It relies on +number of Jakarta-Commons componenets: ul -liDBCP Nightly build gt; 20020523/li -licollections 2.0/li -lipool 1.0/li +liJakarta-Commons DBCP 1.0/li +liJakarta-Commons Collections 2.0/li +liJakarta-Commons Pool 1.0/li /ul -subsection name=Common Requirements -pHere are some common gotchas to consider/p +These jar files along with your the jar file for your JDBC driver should +be installed in code$CATALINA_HOME/common/lib/code. +blockquote +strongNOTE:/strongThird Party drivers should be in jarfiles, not zipfiles. +Tomcat only adds code$CATALINA_HOME/common/lib/*.jar/code to the classpath. +/blockquote +blockquote +strongNOTE:/strong +Do not install these jarfiles in your code/WEB-INF/lib/code, or +code$JAVA_HOME/jre/lib/ext/code, or anywhere else. You will +experience problems if you install them anyplace other than +code$CATALINA_HOME/common/lib/code. +/blockquote +/p + +/subsection + +subsection name=Preventing dB connection pool leaks + +p +A database connection pool creates and manages a pool of connections +to a database. Recycling and reusing already existing connections +to a dB is more efficient than opening a new connection. +/p + +p +There is one problem with
cvs commit: jakarta-tomcat-4.0/webapps/tomcat-docs jndi-datasource-examples-howto.xml project.xml
remm2002/07/03 10:42:54 Modified:webapps/tomcat-docs project.xml Added: webapps/tomcat-docs jndi-datasource-examples-howto.xml Log: - Add some example configurations for the datasources. Much sought after information :) - Thanks to Leslie Hughes leslie.hughes at rubus.com and David Haraburda david-tomcat at haraburda.com Revision ChangesPath 1.14 +2 -0 jakarta-tomcat-4.0/webapps/tomcat-docs/project.xml Index: project.xml === RCS file: /home/cvs/jakarta-tomcat-4.0/webapps/tomcat-docs/project.xml,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- project.xml 9 Sep 2001 22:43:48 - 1.13 +++ project.xml 3 Jul 2002 17:42:53 - 1.14 @@ -26,6 +26,8 @@ item name=Config. Reference href=config/index.html/ item name=Class Loader HOW-TO href=class-loader-howto.html/ item name=JNDI Resources HOW-TO href=jndi-resources-howto.html/ +item name=JNDI DataSource Examples + href=jndi-datasource-examples-howto.html/ item name=Manager App HOW-TOhref=manager-howto.html/ item name=Proxy Support HOW-TO href=proxy-howto.html/ item name=Realm HOW-TO href=realm-howto.html/ 1.1 jakarta-tomcat-4.0/webapps/tomcat-docs/jndi-datasource-examples-howto.xml Index: jndi-datasource-examples-howto.xml === ?xml version=1.0? !DOCTYPE document [ !ENTITY project SYSTEM project.xml ] document project; properties author email=[EMAIL PROTECTED]Les Hughes/author author email=[EMAIL PROTECTED]David Haraburda/author titleJNDI Datasource Examples HOW-TO/title /properties body section name=Introduction pJNDI Datasource configuration is covered extensively in the JNDI-Resources-HOWTO however, feedback from codetomcat-user/code has shown that specifics for individual configurations can be rather tricky./p pHere then are some example configurations that have posted to tomcat-user for popular databases./p /section section name=Jakarta DBCP Pooled Configurations pFor each of these configurations you will need the following Jakarta Commons projects Note that currently, these all employ connection pooling via the Jakarta-commons connection pool. Also, you should be aware that since these notes are derived from the mysql configuration and/or feedback from codetomcat-user/code. YMMV :-). Please let us 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 ul liDBCP Nightly build 20020523/li licollections 2.0/li lipool 1.0/li /ul subsection name=Common Requirements pHere are some common gotchas to consider/p ul liDatasource related classes (drivers, pools etc) should be installed in code$CATALINA_HOME/common/lib/code to enable the server to find your classes when it creates your Datasources/li liThird Party drivers should be in jarfiles, not zipfiles as by default, Tomcat only adds code$CATALINA_HOME/common/lib/*.jar/code to the classpath/li /ul /subsection subsection name=mySQL using Jakarta Commons Connection Pool h30. Software Manifest/h3 pStarting with the correct sotftware is manifestly important, so here's a list of what we've found to work. Let us know of your success stories with other versions./p ul liTomcat 4.0.3/li limySQL 4.0.1alpha/li limm.mysql 2.0.14 (JDBC Driver)/li /ul h31. Installation/h3 pEnsure that you follow these instructions as variations can cause problems./p ul liInstall mm.mysql driver, DBCP, collections and pool jarfiles into code$CATALINA_HOME/common/lib/code. You will experience problems if you place these jarfiles in your webapp's codeWEB-INF/lib/code directory, in your code$JAVA_HOME/jre/lib/ext/code or anywhere else, so dont./li liCreate a new test user, a new database and a single test table. Your mySQL user bmust/b have a password assigned. The driver will fail if you try to connect with an empty password./li/ul source mysqlgt; GRANT ALL PRIVILEGES ON *.* TO javauser@localhost -gt; IDENTIFIED BY 'javadude' WITH GRANT OPTION; mysqlgt; create database javatest; mysqlgt; use javatest; mysqlgt; create table testdata ( -gt; id int not null auto_increment primary key, -gt; foo varchar(25), -gt; bar int); /source pNote: the above user should be removed once testing is complete!/p ulliNext insert some test data into the testdata table/li/ul source mysqlgt; insert into testdata