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