tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roberts, Eric" <>
Subject RE: Connection Pooling Help
Date Mon, 09 Dec 2002 13:33:11 GMT


      Context ctx = new InitialContext();
	Context envCtx = (Context) ctx.lookup("java:/comp/env/");
	DataSource ds = (DataSource) envCtx.lookup("/jdbc/shiltonDB");

-----Original Message-----
From: Kevin Passey []
Sent: Montag, 09. Dezember 2002 14:25
To: Tomcat Users List (E-mail)
Subject: Connection Pooling Help


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

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
















I have added this to my WEB-INF web.xml file:-



            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.












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("<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)

         if (ds != null) {
            Connection conn = ds.getConnection();

            if (conn != null) {
               out.println("<b>Got Connection:</b> " + conn.toString() +
               Statement stmt = conn.createStatement();
               String sql = "select * from BSSTYL";
               ResultSet rst = stmt.executeQuery(sql);
               if ( {
                  out.println("<b>Value of HDCUST on first record:</b> "+
                  	rst.getString("dbfield1")+ "<p>");
               out.println("This was our little database-access
      } catch (Exception e) {

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


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message