You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kevin Passey <kp...@kdpsoftware.co.uk> on 2002/12/09 14:25:14 UTC
Connection Pooling Help
Hi,
Can somebody point out my mistake for me - I'm starting to bang my head..
I am trying to get connection pooling working on my AS/400 using the
Commons-DBCP.
I have placed this JAR in <TOMCAT_HOME>/common/lib along with the JT400.JAR
I have added the context entries to my server.xml file - thus:-
<!-- AS400 Connection Pooling Test -->
<Context path="/shilton" docBase="shilton" debug="5"
reloadable="true" crossContext="true">
<Resource name="jdbc/shiltonDB" auth="Container"
type="javax.sql.DataSource" />
<ResourceParams name="jdbc/shiltonDB">
<parameter>
<name>factory</name>
<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30000</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>100</value>
</parameter>
<parameter>
<name>username</name>
<value>INTERNET</value>
</parameter>
<parameter>
<name>password</name>
<value>INTERNET</value>
</parameter>
<parameter>
<name>driverClassName</name>
<value>com.ibm.as400.access.AS400JDBCDriver</value>
</parameter>
<parameter>
<name>url</name>
<value>jdbc:as400://10.0.0.1</value>
</parameter>
</ResourceParams>
</Context>
I have added this to my WEB-INF web.xml file:-
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
jdbc/shiltonDB
</res-ref-name>
<res-type>
javax.sql.DataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
And I have this java program to test the connection
import javax.naming.*;
import javax.sql.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletOutputStream;
import java.sql.*;
public class DBCPServlet extends HttpServlet {
public void doGet(HttpServletRequest req,
HttpServletResponse res) {
try {
ServletOutputStream out = res.getOutputStream();
out.println("<html><body>");
out.println("<h2>Using Tomcat Connection Pooling with DBCP</h2>");
Context ctx = new InitialContext();
if (ctx == null)
out.println("Something is wrong with Tomcat");
DataSource ds = (DataSource)
ctx.lookup("java:comp/env/jdbc/shiltonDB");
if (ds != null) {
Connection conn = ds.getConnection();
if (conn != null) {
out.println("<b>Got Connection:</b> " + conn.toString() +
"<p>");
Statement stmt = conn.createStatement();
String sql = "select * from BSSTYL";
ResultSet rst = stmt.executeQuery(sql);
if (rst.next()) {
out.println("<b>Value of HDCUST on first record:</b> "+
rst.getString("dbfield1")+ "<p>");
}
out.println("This was our little database-access
servlet...");
conn.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* if somebody does a http-post, we do an interal dispatch to doGet()
*/
public void doPost(HttpServletRequest req,
HttpServletResponse res) {
doGet(req, res);
}
}
"ds" is alway null - what am I missing.
Thanks in advance.
Kevin
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>