Re: Tomcat "JNDI Datasource How-To" documentation & driver managers
Thank you - very helpful & much appreciated. On Sat, Aug 14, 2021 at 4:24 PM Mark Thomas wrote: > On 14/08/2021 01:51, Andrew Tanton wrote: > > In the Tomcat "JNDI Datasource How-To" documentation page > > < > http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#comments_section > >, > > there is an unusually opinionated section, which discusses the Java > service > > provider (driver manager) mechanism: > > I suspect that was me after spending quite a but of time unpicking > various issues associated with DriverManager where Tomcat was getting > blamed. Goes to check the history... > > Yep. Here is the bug report: > https://bz.apache.org/bugzilla/show_bug.cgi?id=52025 > which triggered this doc update: > https://svn.apache.org/viewvc?view=revision=1184919 > > > "*However, the implementation is fundamentally broken in all Java > versions > > for a servlet container environment. The problem is > > that java.sql.DriverManager will scan for the drivers only once.*" > > > > Can someone help me understand what this means in more practical terms? > > This will be a lot simpler to explain with the source code to hand: > > https://github.com/openjdk/jdk/blob/master/src/java.sql/share/classes/java/sql/DriverManager.java > > > The page goes on to say: > > > > "*...web applications that have database drivers in > > their WEB-INF/lib directory cannot rely on the service provider mechanism > > and should register the drivers explicitly.*" > > > > And, indeed, I have found that placing my JDBC driver in Tomcat's > > $CATALINA_HOME/lib > > or $CATALINA_BASE/lib will be loaded correctly, without explicit > > registration. > > > > MY QUESTIONS: > > > > (1) I don't understand why the "scan only once" limitation results in > this > > behavior - so what am I missing, here, conceptually? > > There are several inter-related elements. > > Scan once caused problems as if two web apps both have JDBC drivers then > the DriverManager scan will only load the Driver for the app that > triggers the scan first. > > An added complication is that the memory leak protection code > essentially ensures that the scan is performed by Tomcat internal code > so no JDBC drivers in WEB-INF/lib for any wweb application are seen by > the scan. Hence, the JDBC drivers need to be in CATALINA_BASE/lib. > > (2) Where is this "scan only once" behavior documented? > > It is sort of implied in the DriverManager Javadoc but you need to read > the source code to get a clear picture. > > > (3) What is it about a servlet container environment which allows this > > problem to exist? > > Dynamic loading and unloading of web applications and use of a dedicated > class loader per web application. > > You can also get various memory leaks associated with DriverManager as > well (which Tomcat automatically protects you against). > > Mark > > > > > > Thank you. > > > > For reference, here is the documentation link I used above: > > > > > > > http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html > > > > (The wording in the documentation has been this way for several Tomcat > > versions, going back a few years.) > > > > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > >
Re: Tomcat "JNDI Datasource How-To" documentation & driver managers
On 14/08/2021 01:51, Andrew Tanton wrote: In the Tomcat "JNDI Datasource How-To" documentation page <http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#comments_section>, there is an unusually opinionated section, which discusses the Java service provider (driver manager) mechanism: I suspect that was me after spending quite a but of time unpicking various issues associated with DriverManager where Tomcat was getting blamed. Goes to check the history... Yep. Here is the bug report: https://bz.apache.org/bugzilla/show_bug.cgi?id=52025 which triggered this doc update: https://svn.apache.org/viewvc?view=revision=1184919 "*However, the implementation is fundamentally broken in all Java versions for a servlet container environment. The problem is that java.sql.DriverManager will scan for the drivers only once.*" Can someone help me understand what this means in more practical terms? This will be a lot simpler to explain with the source code to hand: https://github.com/openjdk/jdk/blob/master/src/java.sql/share/classes/java/sql/DriverManager.java The page goes on to say: "*...web applications that have database drivers in their WEB-INF/lib directory cannot rely on the service provider mechanism and should register the drivers explicitly.*" And, indeed, I have found that placing my JDBC driver in Tomcat's $CATALINA_HOME/lib or $CATALINA_BASE/lib will be loaded correctly, without explicit registration. MY QUESTIONS: (1) I don't understand why the "scan only once" limitation results in this behavior - so what am I missing, here, conceptually? There are several inter-related elements. Scan once caused problems as if two web apps both have JDBC drivers then the DriverManager scan will only load the Driver for the app that triggers the scan first. An added complication is that the memory leak protection code essentially ensures that the scan is performed by Tomcat internal code so no JDBC drivers in WEB-INF/lib for any wweb application are seen by the scan. Hence, the JDBC drivers need to be in CATALINA_BASE/lib. > (2) Where is this "scan only once" behavior documented? It is sort of implied in the DriverManager Javadoc but you need to read the source code to get a clear picture. (3) What is it about a servlet container environment which allows this problem to exist? Dynamic loading and unloading of web applications and use of a dedicated class loader per web application. You can also get various memory leaks associated with DriverManager as well (which Tomcat automatically protects you against). Mark Thank you. For reference, here is the documentation link I used above: http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html (The wording in the documentation has been this way for several Tomcat versions, going back a few years.) - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Tomcat "JNDI Datasource How-To" documentation & driver managers
In the Tomcat "JNDI Datasource How-To" documentation page <http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html#comments_section>, there is an unusually opinionated section, which discusses the Java service provider (driver manager) mechanism: "*However, the implementation is fundamentally broken in all Java versions for a servlet container environment. The problem is that java.sql.DriverManager will scan for the drivers only once.*" Can someone help me understand what this means in more practical terms? The page goes on to say: "*...web applications that have database drivers in their WEB-INF/lib directory cannot rely on the service provider mechanism and should register the drivers explicitly.*" And, indeed, I have found that placing my JDBC driver in Tomcat's $CATALINA_HOME/lib or $CATALINA_BASE/lib will be loaded correctly, without explicit registration. MY QUESTIONS: (1) I don't understand why the "scan only once" limitation results in this behavior - so what am I missing, here, conceptually? (2) Where is this "scan only once" behavior documented? (3) What is it about a servlet container environment which allows this problem to exist? Thank you. For reference, here is the documentation link I used above: http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto.html (The wording in the documentation has been this way for several Tomcat versions, going back a few years.)
Re: Tomcat JNDI Datasource
On 2/6/2014 10:45 PM, Filip Hanik wrote: Yes, define the connection pool in server.xml, GlobalNamingResources then in context.xml define a ContextLink That binds the shared connection pool to each context. Thank you, that worked perfectly. Although I think you meant ResourceLink. -Dave - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Tomcat JNDI Datasource
I have defined a JNDI JDBC datasource as a resource in the global context.xml file. I was under the impression that what this does is to create a shared connection pool that is tomcat wide. But in practice what seems to happen is that a new instance of that connection pool is created for each context that is running in the container. For example, if I have 6 web applications deployed I end up with 60 connections to my database, assuming the default initialSize parameter of 10. Is there a way to have a single connection pool that is shared amongst deployed applications? In case it is relevant this is tomcat 7.0.19 using the tomcat connection pool. Thanks -Dave
Re: Tomcat JNDI Datasource
Yes, define the connection pool in server.xml, GlobalNamingResources then in context.xml define a ContextLink That binds the shared connection pool to each context. On Thursday, February 6, 2014, David Newman dnew...@unixmonkeys.com wrote: I have defined a JNDI JDBC datasource as a resource in the global context.xml file. I was under the impression that what this does is to create a shared connection pool that is tomcat wide. But in practice what seems to happen is that a new instance of that connection pool is created for each context that is running in the container. For example, if I have 6 web applications deployed I end up with 60 connections to my database, assuming the default initialSize parameter of 10. Is there a way to have a single connection pool that is shared amongst deployed applications? In case it is relevant this is tomcat 7.0.19 using the tomcat connection pool. Thanks -Dave
RE: Tomcat JNDI datasource
It was this David. 5.0 is a little different. Thanks to all that helped out! Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical auth=Container type=javax.sql.DataSource/ ResourceParams name=jdbc/medical parameter namemaxActive/name value10/value /parameter parameter namemaxIdle/name value1/value /parameter parameter namemaxWait/name value1/value /parameter parameter nameusername/name valueuser/value /parameter parameter namepassword/name valuepassword/value /parameter parameter namedriverClassName/name valuecom.ibm.db2.jcc.DB2Driver/value /parameter parameter nameurl/name valuejdbc:db2://server:5/medical/value /parameter /ResourceParams /Context Also Chris we still use 5.0 tomcat because we are still on Java 1.4, although we will on Java 5 very soon. We are stuck in the past like a Simon and Simon re-run... Tom -Original Message- From: David Smith [mailto:[EMAIL PROTECTED] Sent: Friday, March 28, 2008 10:19 AM To: Tomcat Users List Subject: Re: Tomcat JNDI datasource Just had a brainstorm while responding on another post. The docs for 5.0.30 should describe defining a resource in terms of a Resource ... / element and a ResourceParams/ResourceParams element. The resource as setup below is only correct for version 5.5.x and later. --David Tom Henricksen wrote: I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto . html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSourc e .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.j a va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic a tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil t erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal v e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveC o ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java: 5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCo n textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextVal v e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveC o ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke
Tomcat JNDI datasource
I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC onnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57 7) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:684) at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NullPointerException at java.util.StringTokenizer.init(StringTokenizer.java:146) at com.ibm.db2.jcc.DB2Driver.acceptsURL(DB2Driver.java:245) at java.sql.DriverManager.getDriver(DriverManager.java:232) at
Re: Tomcat JNDI datasource
Hi try this InitialContext ic = new InitialContext(); DataSource ODS = (javax.sql.DataSource) ic.lookup(java:comp/env/jdbc/medical); Connection conn = ODS.getConnection(); It works for me in Oracle 10G on TC with regards Karthik I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC onnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57 7) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:684) at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NullPointerException at
Re: Tomcat JNDI datasource
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom, Tom Henricksen wrote: | org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver | of class '' for connect URL 'null' Aah, yes. The old connect URL 'null' problem. This is always a problem with some nitpicky detail in your configuration, /or/ that you have your driver JAR in the wrong place (or too many places). First check to see where you have put db2driver.jar (or whatever DB2 calls its driver library). It should only exist in one place. Since you have your DataSource configuration in your context.xml, I think that you can simply put it into your application's lib directory and leave it at that. However, if you also have it in your TOMCAT_HOME/(common|shared)/lib, things won't work. Pick one location and stick with it. I have my MySQL driver in one place only: TOMCAT_HOME/common/lib and nowhere else. | I have an application in Tomcat 5.0.30 that we are trying to get to use | JDBC through JNDI. Since you are making such a change, would upgrading Tomcat be a possibility? Tomcat 5.0 is no longer supported. Upgrading to 5.5 should not be all that painful. | I have setup the context.xml | | | | Context debug=4 | docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web | path=/bop-med reloadable=true | workDir=work\Catalina\localhost\bop-med Bad boy: take out the docBase and path attributes. At best, they will be ignored. At worse, they will confuse both you /and/ Tomcat. Feel free to leave workDir in there, though it is not required. Unless you /need/ to specify it, you should take that out and let Tomcat do what it wants. | Resource name=jdbc/medical | type=javax.sql.DataSource | password=password | driverClassName=com.ibm.db2.jcc.DB2Driver | maxIdle=2 | maxWait=5000 | validationQuery=select * from sysibm.SYSDUMMY1 | username=user | url=jdbc:db2://server:5/db | maxActive=4/ | /Context In my configuration, i also have: auth=Container Note that setting the validationQuery without also setting testOnBorrow=true will result in the validationQuery being ignored. | And I have setup the web.xml with | | | | resource-ref | descriptionDB Connection/description | res-ref-namejdbc/medical/res-ref-name | res-typejavax.sql.DataSource/res-type | res-authContainer/res-auth | /resource-ref Technically, you don't need this, but it's not a bad idea to leave it in there. | initCtx = new InitialContext(); | Context envCtx = (Context) initCtx.lookup(java:comp/env); | DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); | | Connection conn = ds.getConnection(); | | System.out.println(DB Version : | + conn.getMetaData().getDatabaseMajorVersion()); | | conn.close(); This code looks fine (though you don't really have to do two separate lookups -- you can combine them into a single lookup). When you get it working, you should be checking for null, catching NamingExceptions and stuff like that, too. But this should work. Hope that helps, - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkftAZMACgkQ9CaO5/Lv0PAy+gCgn4uSwY+hSQiQcTLb7lYIg04F uNcAnAo2QhichFNbHa4P24h7IA1X0XK4 =tR4e -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tomcat JNDI datasource
Your root cause seems to indicate it's having some trouble possibly with the url: Caused by: java.lang.NullPointerException at java.util.StringTokenizer.init(StringTokenizer.java:146) at com.ibm.db2.jcc.DB2Driver.acceptsURL(DB2Driver.java:245) at java.sql.DriverManager.getDriver(DriverManager.java:232) Not having much experience with IBM's db2 driver, I don't have any good suggestions, but it's something to look at. Also your validation query looks like it could potentially return a lot of records. The validation query only needs to be something simple like 'select 1' -- just enough to fire off some traffic to the server and get a positive response. Tom Henricksen wrote: I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9)
Re: Tomcat JNDI datasource
Hi. Did you try putting your .jar files in \WEB-INF\lib of you webapp? Tom Henricksen [EMAIL PROTECTED] 3/28/2008 8:08 AM I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC onnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57 7) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:684) at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NullPointerException at java.util.StringTokenizer.init(StringTokenizer.java:146) at com.ibm.db2.jcc.DB2Driver.acceptsURL(DB2Driver.java:245)
Re: Tomcat JNDI datasource
| Context debug=4 | docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web | path=/bop-med reloadable=true | workDir=work\Catalina\localhost\bop-med Bad boy: take out the docBase and path attributes. At best, they will be ignored. At worse, they will confuse both you /and/ Tomcat. Feel free to leave workDir in there, though it is not required. Unless you /need/ to specify it, you should take that out and let Tomcat do what it wants. Not necessarily bad. He's deploying the app from outside the tomcat webapps directory, so at least docBase is good. The path on the other hand would be picked up from the name of the context xml file in conf/Catalina/localhost. Note that setting the validationQuery without also setting testOnBorrow=true will result in the validationQuery being ignored. Last I looked, testOnBorrow is true by default and only needs a validationQuery. Setting it explicitly won't hurt though. --David Christopher Schultz wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Tom, Tom Henricksen wrote: | org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver | of class '' for connect URL 'null' Aah, yes. The old connect URL 'null' problem. This is always a problem with some nitpicky detail in your configuration, /or/ that you have your driver JAR in the wrong place (or too many places). First check to see where you have put db2driver.jar (or whatever DB2 calls its driver library). It should only exist in one place. Since you have your DataSource configuration in your context.xml, I think that you can simply put it into your application's lib directory and leave it at that. However, if you also have it in your TOMCAT_HOME/(common|shared)/lib, things won't work. Pick one location and stick with it. I have my MySQL driver in one place only: TOMCAT_HOME/common/lib and nowhere else. | I have an application in Tomcat 5.0.30 that we are trying to get to use | JDBC through JNDI. Since you are making such a change, would upgrading Tomcat be a possibility? Tomcat 5.0 is no longer supported. Upgrading to 5.5 should not be all that painful. | I have setup the context.xml | | | | Context debug=4 | docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web | path=/bop-med reloadable=true | workDir=work\Catalina\localhost\bop-med Bad boy: take out the docBase and path attributes. At best, they will be ignored. At worse, they will confuse both you /and/ Tomcat. Feel free to leave workDir in there, though it is not required. Unless you /need/ to specify it, you should take that out and let Tomcat do what it wants. | Resource name=jdbc/medical | type=javax.sql.DataSource | password=password | driverClassName=com.ibm.db2.jcc.DB2Driver | maxIdle=2 | maxWait=5000 | validationQuery=select * from sysibm.SYSDUMMY1 | username=user | url=jdbc:db2://server:5/db | maxActive=4/ | /Context In my configuration, i also have: auth=Container Note that setting the validationQuery without also setting testOnBorrow=true will result in the validationQuery being ignored. | And I have setup the web.xml with | | | | resource-ref | descriptionDB Connection/description | res-ref-namejdbc/medical/res-ref-name | res-typejavax.sql.DataSource/res-type | res-authContainer/res-auth | /resource-ref Technically, you don't need this, but it's not a bad idea to leave it in there. | initCtx = new InitialContext(); | Context envCtx = (Context) initCtx.lookup(java:comp/env); | DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); | | Connection conn = ds.getConnection(); | | System.out.println(DB Version : | + conn.getMetaData().getDatabaseMajorVersion()); | | conn.close(); This code looks fine (though you don't really have to do two separate lookups -- you can combine them into a single lookup). When you get it working, you should be checking for null, catching NamingExceptions and stuff like that, too. But this should work. Hope that helps, - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkftAZMACgkQ9CaO5/Lv0PAy+gCgn4uSwY+hSQiQcTLb7lYIg04F uNcAnAo2QhichFNbHa4P24h7IA1X0XK4 =tR4e -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To start a new topic, e-mail:
Re: Tomcat JNDI datasource
Bad suggestion. It should exist in one and only one place. That place is common/lib for tc 5.0, 5.5 so it's visible to both tomcat's internal code and the webapp. --David Howard Watson wrote: Hi. Did you try putting your .jar files in \WEB-INF\lib of you webapp? Tom Henricksen [EMAIL PROTECTED] 3/28/2008 8:08 AM I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC onnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57 7) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:684) at java.lang.Thread.run(Thread.java:534) Caused by:
Re: Tomcat JNDI datasource
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 David, David Smith wrote: | | | Context debug=4 | | docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web | | path=/bop-med reloadable=true | | workDir=work\Catalina\localhost\bop-med | | Bad boy: take out the docBase and path attributes. At best, they will be | ignored. At worse, they will confuse both you /and/ Tomcat. Feel free to | leave workDir in there, though it is not required. Unless you /need/ to | specify it, you should take that out and let Tomcat do what it wants. | | Not necessarily bad. He's deploying the app from outside the tomcat | webapps directory, so at least docBase is good. Tomcat needs to know where to find the application in the first place. Since context.xml is in the application, there's no need for the application to re-assert its own location. It can only be wrong about it. | The path on the other | hand would be picked up from the name of the context xml file in | conf/Catalina/localhost. I'm assuming (perhaps incorrectly) that context.xml really meant context.xml, and not an application-specific xml file in the conf directory. | Note that setting the validationQuery without also setting | testOnBorrow=true will result in the validationQuery being ignored. | | Last I looked, testOnBorrow is true by default and only needs a | validationQuery. Setting it explicitly won't hurt though. Oops, I always remember that one backward. testOnBorrow=true by default, but there's no default validationQuery, so it has no effect. Setting validationQuery=[something] will definitely turn it on. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.8 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkftBPEACgkQ9CaO5/Lv0PAfYQCgrdxUDgs7vsh4BUCp9dalZK/y e88AoKrdMuzbiS57d/jGfWM1J6C8lx8+ =HZb2 -END PGP SIGNATURE- - To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Tomcat JNDI datasource
If the app still had errors with the .jar file in the webapps own \WEB-INF\lib then something else is broken (called a test). Since his webapp docBase is outside the Tomcat directory structure there is merit with having associated .jar files in that docBase. And in instances where there are multiple Tomcats running and perhaps multiple versions, then keeping associated files with your app has merit also. David Smith [EMAIL PROTECTED] 3/28/2008 8:45 AM Bad suggestion. It should exist in one and only one place. That place is common/lib for tc 5.0, 5.5 so it's visible to both tomcat's internal code and the webapp. --David Howard Watson wrote: Hi. Did you try putting your .jar files in \WEB-INF\lib of you webapp? Tom Henricksen [EMAIL PROTECTED] 3/28/2008 8:08 AM I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at
Re: Tomcat JNDI datasource
It does have merit to keep associated jars together except in those rare occasions where the jar has to be in the classloader heirarchy at a place visible to both tomcat's internal code and the webapp's. In that case it has to be in common/lib and not in any descendant classloader. To do what you suggest requires the app have it's own pooling library and use the factory attribute in the Resource def. --David Howard Watson wrote: If the app still had errors with the .jar file in the webapps own \WEB-INF\lib then something else is broken (called a test). Since his webapp docBase is outside the Tomcat directory structure there is merit with having associated .jar files in that docBase. And in instances where there are multiple Tomcats running and perhaps multiple versions, then keeping associated files with your app has merit also. David Smith [EMAIL PROTECTED] 3/28/2008 8:45 AM Bad suggestion. It should exist in one and only one place. That place is common/lib for tc 5.0, 5.5 so it's visible to both tomcat's internal code and the webapp. --David Howard Watson wrote: Hi. Did you try putting your .jar files in \WEB-INF\lib of you webapp? Tom Henricksen [EMAIL PROTECTED] 3/28/2008 8:08 AM I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at
Re: Tomcat JNDI datasource
Just had a brainstorm while responding on another post. The docs for 5.0.30 should describe defining a resource in terms of a Resource ... / element and a ResourceParams/ResourceParams element. The resource as setup below is only correct for version 5.5.x and later. --David Tom Henricksen wrote: I have an application in Tomcat 5.0.30 that we are trying to get to use JDBC through JNDI. I am trying to follow along with akarta-tomcat-5.0.30/webapps/tomcat-docs/jndi-datasource-examples-howto. html. I have setup the context.xml Context debug=4 docBase=C:/Java/eclipse-europa/europa-workspace/bop-med/web path=/bop-med reloadable=true workDir=work\Catalina\localhost\bop-med Resource name=jdbc/medical type=javax.sql.DataSource password=password driverClassName=com.ibm.db2.jcc.DB2Driver maxIdle=2 maxWait=5000 validationQuery=select * from sysibm.SYSDUMMY1 username=user url=jdbc:db2://server:5/db maxActive=4/ /Context And I have setup the web.xml with resource-ref descriptionDB Connection/description res-ref-namejdbc/medical/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref When I call the following code initCtx = new InitialContext(); Context envCtx = (Context) initCtx.lookup(java:comp/env); DataSource ds = (DataSource) envCtx.lookup(jdbc/medical); Connection conn = ds.getConnection(); System.out.println(DB Version : + conn.getMetaData().getDatabaseMajorVersion()); conn.close(); I get the following error org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null' at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource .java:780) at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.ja va:540) at com.advtechgrp.web.servlet.TestConn.processRequest(TestConn.java:37) at com.advtechgrp.web.servlet.TestConn.doGet(TestConn.java:20) at javax.servlet.http.HttpServlet.service(HttpServlet.java:689) at javax.servlet.http.HttpServlet.service(HttpServlet.java:802) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica tionFilterChain.java:252) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt erChain.java:173) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv e.java:214) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardCon textValve.java:198) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv e.java:152) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java :137) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java :118) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:102) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve. java:109) at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveCo ntext.java:104) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:5 20) at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929) at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:79 9) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processC onnection(Http11Protocol.java:705) at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:57 7) at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool .java:684) at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NullPointerException