Results 1 to 1 of 1
  1. #1
    zrrbite is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default 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.

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

    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.

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

Similar Threads

  1. Tomcat In Eclipse - Sysdeo Tomcat Plug-in
    By JavaForums in forum Eclipse
    Replies: 1
    Last Post: 02-13-2008, 11:33 AM
  2. Jakarta POI 3.0
    By levent in forum Java Software
    Replies: 1
    Last Post: 11-12-2007, 07:23 AM
  3. Commons Library Framework 0.8.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-02-2007, 05:13 PM
  4. Commons validator
    By aczuczor in forum Web Frameworks
    Replies: 0
    Last Post: 07-27-2007, 09:46 AM
  5. JAKARTA STRUTS book
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-01-2007, 05:36 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •