RE: JDBC/DBCP problems
Hi Jay, I don't know if it's of any help at all, but I went through something similar. What I found to be my problem was that my URLs for invoking JSPs/servlets did not always specify my Tomcat Context and all the DataSource stuff was set up in my context (in server.xml and the associated web.xml). Since I had pointed the default Context / to my Context (/hal) by setting it's docBase in server.xml most of the requests appeared to be working. For example, if I asked for {host}/jsp/myJSP.jsp I would get in fact reach the JSP at... {host}/hal/jsp/myJSP.jsp) but the JNDI stuff did not get picked up. Leaving the /hal out of my request meant it never saw the /hal stuff in server.xml which is where my DataSource stuff lives. I cleaned up my URL in links/forms etc. and seemed to get on okay. Hope it helps a bit. Best regards Chris -Original Message- From: Burgess, Jay S [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 3:36 PM To: [EMAIL PROTECTED] Subject: JDBC/DBCP problems I'm obviously missing something important with regards to moving our database/JDBC connectivity to use JNDI DataSource/DBCP. I've read and re-read the docs, looked at every related message in the archive, and Google'd every set of keywords I can think of, but still no luck. Here's the issue: Tomcat version is 4.1.29 on Windows XP. I'm attempting to connect to SQL Server. The JDBC driver JARs are in CATALINA_HOME\common\lib, and since everything works fine if I manually load the driver via Class.forName(), I don't think my problem is related to my driver files location. When attempting to use getConnection(), however, I get the dreaded Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver error. The highlights of my configuration are below. - SERVER.XML - GlobalNamingResources Resource name=jdbc/mydb auth=Container type=javax.sql.DataSource description=The database. / ResourceParams name=jdbc/mydb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter nameurl/name valuejdbc:microsoft:sqlserver://###.###.###.###:1433;Databas e=MyDB/va lue /parameter parameter namedriverClassName/name valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value /parameter parameter nameusername/name valueMyUsername/value /parameter parameter namepassword/name valueMyPassword/value /parameter ... /GlobalNamingResources - WEB.XML - resource-ref descriptionSome description. /description res-ref-namejdbc/mydb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref - In my servlet's init(): - Context initialContext = new InitialContext(); Context envContext = (Context) initialContext.lookup(java:comp/env); DataSource dataSource = (DataSource) envContext.lookup(jdbc/mydb); Connection conn = dataSource.getConnection(); // throws exception - Further info: - Adding the following line after acquiring dataSource above, I get class org.apache.commons.dbcp.BasicDataSource: System.out.println(dataSource.getClass()); And if I add the following, I get [EMAIL PROTECTED]: System.out.println((org.apache.commons.dbcp.BasicDataSource) dataSource); So, since it looks like a valid BasicDataSource object, I tried the following, but get null back: System.out.println(((org.apache.commons.dbcp.BasicDataSource) dataSource).getUrl()); This seems to indicate that the object isn't initialized? Turning on debug for the relevant listeners (NamingContextListener and GlobalResourcesLifecycleListener), I see the following related info in my Tomcat console window, which looks good from what I understand: Jan 28, 2004 9:06:11 AM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on port 8080 NamingContextListener[/]: Creating JNDI naming context NamingContextListener[/]: Resource parameters for mydb = ResourceParams[name=mydb, parameters= {url=jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB, maxIdle=4, maxActive=8, driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver, maxWait=1, removeAbandoned=true, username=MyUsername, factory=org.apache.commons.dbcp.BasicDataSourceFactory, logAbandoned=true, removeAbandonedTimeout=60, password=MyPassword}] NamingContextListener[/]: Adding resource ref mydb NamingContextListener[/]: ResourceRef[ className=javax.sql.DataSource, factoryClassLocation=null, factoryClassName=org.apache.naming.factory.ResourceFactory,
RE: JDBC/DBCP problems
Thanks for the feedback. Maybe my problem does have something to do with context visibility, but since I'm defining the resource within SERVER.XML's GlobalNamingResources, I was under the impression that these resources were available to all contexts. I'll keep plugging away at it with your comments in mind, see if I can uncover anything further, and see if anyone else replies. Thanks. Jay -Original Message- From: Chris Ward [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 10:00 AM To: Tomcat Users List Subject: RE: JDBC/DBCP problems Hi Jay, I don't know if it's of any help at all, but I went through something similar. What I found to be my problem was that my URLs for invoking JSPs/servlets did not always specify my Tomcat Context and all the DataSource stuff was set up in my context (in server.xml and the associated web.xml). Since I had pointed the default Context / to my Context (/hal) by setting it's docBase in server.xml most of the requests appeared to be working. For example, if I asked for {host}/jsp/myJSP.jsp I would get in fact reach the JSP at... {host}/hal/jsp/myJSP.jsp) but the JNDI stuff did not get picked up. Leaving the /hal out of my request meant it never saw the /hal stuff in server.xml which is where my DataSource stuff lives. I cleaned up my URL in links/forms etc. and seemed to get on okay. Hope it helps a bit. Best regards Chris -Original Message- From: Burgess, Jay S [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 3:36 PM To: [EMAIL PROTECTED] Subject: JDBC/DBCP problems I'm obviously missing something important with regards to moving our database/JDBC connectivity to use JNDI DataSource/DBCP. I've read and re-read the docs, looked at every related message in the archive, and Google'd every set of keywords I can think of, but still no luck. Here's the issue: Tomcat version is 4.1.29 on Windows XP. I'm attempting to connect to SQL Server. The JDBC driver JARs are in CATALINA_HOME\common\lib, and since everything works fine if I manually load the driver via Class.forName(), I don't think my problem is related to my driver files location. When attempting to use getConnection(), however, I get the dreaded Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver error. The highlights of my configuration are below. - SERVER.XML - GlobalNamingResources Resource name=jdbc/mydb auth=Container type=javax.sql.DataSource description=The database. / ResourceParams name=jdbc/mydb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter nameurl/name valuejdbc:microsoft:sqlserver://###.###.###.###:1433;Databas e=MyDB/va lue /parameter parameter namedriverClassName/name valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value /parameter parameter nameusername/name valueMyUsername/value /parameter parameter namepassword/name valueMyPassword/value /parameter ... /GlobalNamingResources - WEB.XML - resource-ref descriptionSome description. /description res-ref-namejdbc/mydb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref - In my servlet's init(): - Context initialContext = new InitialContext(); Context envContext = (Context) initialContext.lookup(java:comp/env); DataSource dataSource = (DataSource) envContext.lookup(jdbc/mydb); Connection conn = dataSource.getConnection(); // throws exception - Further info: - Adding the following line after acquiring dataSource above, I get class org.apache.commons.dbcp.BasicDataSource: System.out.println(dataSource.getClass()); And if I add the following, I get [EMAIL PROTECTED]: System.out.println((org.apache.commons.dbcp.BasicDataSource) dataSource); So, since it looks like a valid BasicDataSource object, I tried the following, but get null back: System.out.println(((org.apache.commons.dbcp.BasicDataSource) dataSource).getUrl()); This seems to indicate that the object isn't initialized? Turning on debug for the relevant listeners (NamingContextListener and GlobalResourcesLifecycleListener), I see the following related info in my Tomcat console window, which looks good from what I understand: Jan 28, 2004 9:06:11 AM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on port 8080 NamingContextListener[/]: Creating JNDI naming context NamingContextListener[/]: Resource parameters for mydb = ResourceParams[name=mydb, parameters= {url
Re: JDBC/DBCP problems
Hi! Burgess, Jay S wrote: Thanks for the feedback. Maybe my problem does have something to do with context visibility, but since I'm defining the resource within SERVER.XML's GlobalNamingResources, I was under the impression that these resources were available to all contexts. I had a similar problem. It seems, that if you auto-deploy a context by dropping a .war into tomcat's webapps, this context does not see the JNDI-Resources defined in the GlobalNamingResources section of the server.xml. I had to specify them explicitly in it's own Context section for my webapp. This problem seems to be limited to tomcat 4.x, since it vanished after I upgraded to tomcat5. HTH Phil -- And on the seventh day, He exited from append mode. (Book of create(2), line 255) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JDBC/DBCP problems
I think it's a better idea to make those app resources local instead of global. If your app is the only one that needs that data source, by all means it should not be global. That's the way I prefer to do it. Keep those apps uncoupled and isolated from each other. - MOD --- Philipp Taprogge [EMAIL PROTECTED] wrote: Hi! Burgess, Jay S wrote: Thanks for the feedback. Maybe my problem does have something to do with context visibility, but since I'm defining the resource within SERVER.XML's GlobalNamingResources, I was under the impression that these resources were available to all contexts. I had a similar problem. It seems, that if you auto-deploy a context by dropping a .war into tomcat's webapps, this context does not see the JNDI-Resources defined in the GlobalNamingResources section of the server.xml. I had to specify them explicitly in it's own Context section for my webapp. This problem seems to be limited to tomcat 4.x, since it vanished after I upgraded to tomcat5. HTH Phil -- And on the seventh day, He exited from append mode. (Book of create(2), line 255) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] __ Do you Yahoo!? Yahoo! SiteBuilder - Free web site building tool. Try it! http://webhosting.yahoo.com/ps/sb/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JDBC/DBCP problems
Yes, that appears to be my issue. Thank you very much for the input. By the way, I just queried the bug database, and see that there are a number of similar reports out there. They all seem to reference your suggestion of using a Context element though, and since we didn't have an explicit Context element at first, I'm going to look further into whether this is truly a bug, or just my misunderstanding of the relationships. And I'll pay more attention to the bug database next time I run across an issue like this. Thanks again. Jay -Original Message- From: Philipp Taprogge [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 11:36 AM To: Tomcat Users List Subject: Re: JDBC/DBCP problems Hi! Burgess, Jay S wrote: Thanks for the feedback. Maybe my problem does have something to do with context visibility, but since I'm defining the resource within SERVER.XML's GlobalNamingResources, I was under the impression that these resources were available to all contexts. I had a similar problem. It seems, that if you auto-deploy a context by dropping a .war into tomcat's webapps, this context does not see the JNDI-Resources defined in the GlobalNamingResources section of the server.xml. I had to specify them explicitly in it's own Context section for my webapp. This problem seems to be limited to tomcat 4.x, since it vanished after I upgraded to tomcat5. HTH Phil -- And on the seventh day, He exited from append mode. (Book of create(2), line 255) - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: JDBC/DBCP problems
Tomcat version is 4.1.29 on Windows XP. I'm attempting to connect to SQL Server. The JDBC driver JARs are in CATALINA_HOME\common\lib, and since everything works fine if I manually load the driver via Class.forName(), I don't think my problem is related to my driver files location. When attempting to use getConnection(), however, I get the dreaded Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver error. The highlights of my configuration are below. Two comments: 1. You don't mention a ResourceLink. When you define a Resource as global, you need to use a ResourceLink in the definition of the context of the application. In your case, something like ResourceLink global=jdbc/mydb name=jdbc/mydb type=javax.sql.DataSource / inside the Context tag of the server.xml COULD work. 2. I'm saying COULD in the previous comment because I had the same problem and could not solve it with Tomcat 4.1.29. Using 5.0.16 or 5.0.18 everything works fine. I have something like: server.xml GlobalNamingResources Resource name=GlobalDataSource auth=Container type=javax.sql.DataSource description=The database. / ResourceParams name=GlobalDataSource ... /ResourceParams /GlobalNamingResources --- Catalina/host/myapp.xml --- Context ... ResourceLink global=GlobalDataSource name=jdbc/mydb type=javax.sql.DataSource / /Context Note that there's no need of using a resource-ref in web.xml. --- Julio César Aguilar Cabrera [EMAIL PROTECTED] Proyecto SIGC3, LANIA - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JDBC/DBCP problems
You've identified part of my problem, I think. From what I found, none of the documentation that talks about DataSource configuration mentions that ResourceLink is required (e.g. JNDI Datasource HOW-TO). They talk about using resource-ref in WEB.XML instead. I assumed that if you had a Context element in SERVER.XML, then you could also add a ResourceLink within your Context. If you don't have an explicit Context element (as we didn't), or you don't want to define a ResourceLink, then you could use resource-ref in WEB.XML. Now that I've got it working, I can at least try the various configurations and decide what the option(s) are and whether there's truly a bug in 4.1.29. Thanks for the info. Jay -Original Message- From: Julio César Aguilar [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 28, 2004 1:23 PM To: Tomcat Users List Subject: Re: JDBC/DBCP problems Tomcat version is 4.1.29 on Windows XP. I'm attempting to connect to SQL Server. The JDBC driver JARs are in CATALINA_HOME\common\lib, and since everything works fine if I manually load the driver via Class.forName(), I don't think my problem is related to my driver files location. When attempting to use getConnection(), however, I get the dreaded Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver error. The highlights of my configuration are below. Two comments: 1. You don't mention a ResourceLink. When you define a Resource as global, you need to use a ResourceLink in the definition of the context of the application. In your case, something like ResourceLink global=jdbc/mydb name=jdbc/mydb type=javax.sql.DataSource / inside the Context tag of the server.xml COULD work. 2. I'm saying COULD in the previous comment because I had the same problem and could not solve it with Tomcat 4.1.29. Using 5.0.16 or 5.0.18 everything works fine. I have something like: server.xml GlobalNamingResources Resource name=GlobalDataSource auth=Container type=javax.sql.DataSource description=The database. / ResourceParams name=GlobalDataSource ... /ResourceParams /GlobalNamingResources --- Catalina/host/myapp.xml --- Context ... ResourceLink global=GlobalDataSource name=jdbc/mydb type=javax.sql.DataSource / /Context Note that there's no need of using a resource-ref in web.xml. --- Julio César Aguilar Cabrera [EMAIL PROTECTED] Proyecto SIGC3, LANIA - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: JDBC/DBCP problems
Don´t use it in init( ) method, only doPost( ) or doGet( ). -- De: Burgess, Jay S[SMTP:[EMAIL PROTECTED] Responder:Tomcat Users List Enviada: quarta-feira, 28 de janeiro de 2004 12:35 Para: [EMAIL PROTECTED] Assunto: JDBC/DBCP problems I'm obviously missing something important with regards to moving our database/JDBC connectivity to use JNDI DataSource/DBCP. I've read and re-read the docs, looked at every related message in the archive, and Google'd every set of keywords I can think of, but still no luck. Here's the issue: Tomcat version is 4.1.29 on Windows XP. I'm attempting to connect to SQL Server. The JDBC driver JARs are in CATALINA_HOME\common\lib, and since everything works fine if I manually load the driver via Class.forName(), I don't think my problem is related to my driver files location. When attempting to use getConnection(), however, I get the dreaded Cannot create JDBC driver of class '' for connect URL 'null', cause: No suitable driver error. The highlights of my configuration are below. - SERVER.XML - GlobalNamingResources Resource name=jdbc/mydb auth=Container type=javax.sql.DataSource description=The database. / ResourceParams name=jdbc/mydb parameter namefactory/name valueorg.apache.commons.dbcp.BasicDataSourceFactory/value /parameter parameter nameurl/name valuejdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB/va lue /parameter parameter namedriverClassName/name valuecom.microsoft.jdbc.sqlserver.SQLServerDriver/value /parameter parameter nameusername/name valueMyUsername/value /parameter parameter namepassword/name valueMyPassword/value /parameter ... /GlobalNamingResources - WEB.XML - resource-ref descriptionSome description. /description res-ref-namejdbc/mydb/res-ref-name res-typejavax.sql.DataSource/res-type res-authContainer/res-auth /resource-ref - In my servlet's init(): - Context initialContext = new InitialContext(); Context envContext = (Context) initialContext.lookup(java:comp/env); DataSource dataSource = (DataSource) envContext.lookup(jdbc/mydb); Connection conn = dataSource.getConnection(); // throws exception - Further info: - Adding the following line after acquiring dataSource above, I get class org.apache.commons.dbcp.BasicDataSource: System.out.println(dataSource.getClass()); And if I add the following, I get [EMAIL PROTECTED]: System.out.println((org.apache.commons.dbcp.BasicDataSource) dataSource); So, since it looks like a valid BasicDataSource object, I tried the following, but get null back: System.out.println(((org.apache.commons.dbcp.BasicDataSource) dataSource).getUrl()); This seems to indicate that the object isn't initialized? Turning on debug for the relevant listeners (NamingContextListener and GlobalResourcesLifecycleListener), I see the following related info in my Tomcat console window, which looks good from what I understand: Jan 28, 2004 9:06:11 AM org.apache.coyote.http11.Http11Protocol init INFO: Initializing Coyote HTTP/1.1 on port 8080 NamingContextListener[/]: Creating JNDI naming context NamingContextListener[/]: Resource parameters for mydb = ResourceParams[name=mydb, parameters= {url=jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB, maxIdle=4, maxActive=8, driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver, maxWait=1, removeAbandoned=true, username=MyUsername, factory=org.apache.commons.dbcp.BasicDataSourceFactory, logAbandoned=true, removeAbandonedTimeout=60, password=MyPassword}] NamingContextListener[/]: Adding resource ref mydb NamingContextListener[/]: ResourceRef[ className=javax.sql.DataSource, factoryClassLocation=null, factoryClassName=org.apache.naming.factory.ResourceFactory, {type=description,content=The database.}, {type=scope,content=Shareable}, {type=auth,content=Container}, {type=url,content= jdbc:microsoft:sqlserver://###.###.###.###:1433;Database=MyDB}, {type=maxIdle,content=4}, {type=maxActive,content=8}, {type=driverClassName,content=com.microsoft.jdbc.sqlserver.SQLServerDriv er},{type=maxWait,content=1}, {type=removeAbandoned,content=true}, {type=username,content=MyUsername}, {type=factory,content=org.apache.commons.dbcp.BasicDataSourceFactory}, {type=logAbandoned,content=true}, {type=removeAbandonedTimeout,content=60}, {type=password,content=MyPassword}] GlobalResourcesLifecycleListener: Creating MBeans for Global JNDI Resources in Context '' [EMAIL PROTECTED] GlobalResourcesLifecycleListener: Processing resource mydb
Re: JDBC/DBCP problems
Hi! Michael Duffy wrote: I think it's a better idea to make those app resources local instead of global. If your app is the only one that needs that data source, by all means it should not be global. That's the way I prefer to do it. Keep those apps uncoupled and isolated from each other. - MOD Agreed. The problem is that with tomcat4 (at least as far as I have learned), it is not possible to define a Context-Element in server.xml for a webapp that has not yet been deployed. If you want to use auto-deploy, you have to drop the war into the webapps directory, start and then stop tomcat so that the war get's unpacked and the context registered, next you have to add the Context element and finally start tomcat again for those changes to take effect. If you want to define datasources for a webapp that is not yet deployed, you have no choice than to make them global. As I said earlier, this only applies to tomcat4. If I am mistaken here, by all means tell me so, because this bahavior is a pain in the back... Phil - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]