Results 1 to 1 of 1
- 12-14-2007, 12:47 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 1
- Rep Power
- 0
Using jakarta-commons threadpool (Tomcat) through JNDI
Hello everyone!
*EDIT*: I just realized this might be the wrong forum for this question. Hopefully it will get moved.
I'm having some problems getting the jakarta-commons threadpool to work with Tomcat through JDNI. I'm attempting to make use of it from a Java servlet web application in Eclipse.
Prerequisites: I've downloaded the JDBC 2.0 optional package and my jdbc postgres driver are located inmy tomcat/common/lib directory.
Setup: I used tomcats official guide for setting up the server: The Apache Tomcat 5.5 Servlet/JSP Container - JNDI Datasource HOW-TO
I've set up the server.xml as defined in the above guide.
The connection info has been omitted here, but i have checked that it's accurate, and i can create nonpooled connections using this very connectionstring.Java Code:<Resource name="jdbc/TEST" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://127.0.0.1:5432/mydb" username="myuser" password="mypasswd" maxActive="20" maxIdle="10" maxWait="-1"/>
I've registered an external dependency for the application (in web.xml) which matches the resource defined in tomcat/conf/server.xml.
Java Code:<resource-ref> <description>postgreSQL Datasource example</description> <res-ref-name>jdbc/TEST</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
I've registered a ServletContext listener in the application to initialize the context and lookup the connectionpool resource as defined in tomcat/conf/server.xml. I've double checked that all referenced resources haven't been misspelled.
Whenever the context is initialized and it tries to look up the datasource "jdbc/TEST" it's null. The naming context lookup appears to be functioning. Should the lookup be throwing an exception in case the resource does not exist? Am i missing something here?Java Code:package test; import javax.servlet.*; import javax.sql.*; import javax.naming.*; public class DBCPoolingListener implements ServletContextListener{ public void contextInitialized(ServletContextEvent sce) { try { // Obtain environment naming context Context envCtx = (Context) new InitialContext().lookup("java:comp/env"); // Look up data source DataSource ds = (DataSource) envCtx.lookup("jdbc/TEST"); sce.getServletContext().setAttribute("DBCPool", ds); } catch(NamingException e){ e.printStackTrace(); } } public void contextDestroyed(ServletContextEvent sce) {} }
Hope there's enough information to understand the problem.
Thank you in advance!
Regards, MartinLast edited by zrrbite; 12-14-2007 at 12:53 PM.
Similar Threads
-
Tomcat In Eclipse - Sysdeo Tomcat Plug-in
By JavaForums in forum EclipseReplies: 1Last Post: 02-13-2008, 10:33 AM -
Jakarta POI 3.0
By levent in forum Java SoftwareReplies: 1Last Post: 11-12-2007, 06:23 AM -
Commons Library Framework 0.8.0
By JavaBean in forum Java SoftwareReplies: 0Last Post: 10-02-2007, 04:13 PM -
Commons validator
By aczuczor in forum Web FrameworksReplies: 0Last Post: 07-27-2007, 08:46 AM -
JAKARTA STRUTS book
By Ed in forum New To JavaReplies: 2Last Post: 07-01-2007, 04:36 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks