Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-14-2007, 01:47 PM
Member
 
Join Date: Dec 2007
Posts: 1
zrrbite is on a distinguished road
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.

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"/>
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.

I've registered an external dependency for the application (in web.xml) which matches the resource defined in tomcat/conf/server.xml.

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.

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) {} }
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?

Hope there's enough information to understand the problem.
Thank you in advance!

Regards, Martin

Last edited by zrrbite : 12-14-2007 at 01:53 PM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tomcat In Eclipse - Sysdeo Tomcat Plug-in JavaForums Eclipse 1 02-13-2008 11:33 AM
Jakarta POI 3.0 levent Java Announcements 1 11-12-2007 07:23 AM
Commons Library Framework 0.8.0 JavaBean Java Announcements 0 10-02-2007 05:13 PM
Commons validator aczuczor Web Frameworks 0 07-27-2007 09:46 AM
JAKARTA STRUTS book Ed New To Java 2 07-01-2007 05:36 PM


All times are GMT +3. The time now is 06:37 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org