tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Propes, Barry L [GCG-NAOT]" <barry.l.pro...@citigroup.com>
Subject RE: Connection pool problem DBCP - 4.1.3
Date Wed, 21 Feb 2007 16:18:17 GMT
I wonder...would I get mixed results trying to implement JNDI maing in my server.xml file,
but only trying to (on a page by page basis, with an existing servlet and/or JSP) utilize
the naming context method?

In other words, I test out DBCP with one dedicated servlet or JSP, and perhaps it works fine,
but somehow that adversely affects another servlet or JSP where I've not really implemented
the Naming Context portion, but since I've altered the server.xml file, that's affected it?

Please let me know if you have any insight into this.

Thanks!

-----Original Message-----
From: Mike Quilleash [mailto:mike.quilleash@subexazure.com]
Sent: Monday, February 19, 2007 1:08 PM
To: Tomcat Users List
Subject: RE: Connection pool problem DBCP - 4.1.3


Need a bit more info.  DB type and version, JDBC driver version,
ResultSet loop/access code.

Generally the pseudo code should be...


Open Connection
try
{
  Prepare Statement
  try
  {
    Execute Query
    try
    {
      while ( resultSet.next() )
      {
        // process row here
      }
    }
    finally
    {
      Close ResultSet
    }
  }
  finally
  {
    Close PreparedStatement 
  }
}
finally
{
  Close Connection
}


All of the closing should be done in finally blocks so they happen even
if you get an exception.

-----Original Message-----
From: Propes, Barry L [GCG-NAOT] [mailto:barry.l.propes@citigroup.com] 
Sent: 19 February 2007 18:22
To: Tomcat Users List
Subject: Connection pool problem DBCP - 4.1.3


This is driving me crazy. I'm finally close, I think, on getting this
solved.

Problem is I seem to either get Connection is closed or Exhausted
resultset, depending where I put my close statement.


I've got the following up at the top, which replaces my driver reference
that was previously there.

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env"); // Look up
our data source DataSource ds = (DataSource)
  envCtx.lookup("jdbc/myoracle");
// Allocate and use a connection from the pool Connection connection =
ds.getConnection();

Statement selstmt = connection.createStatement();

String prepSQL = "SELECT AID, ACTIVE, REQUESTOR_NAME...," +
		 "PHONE_NUM,DATE_REQ,... " +
                          "...." +
		 "FROM table a INNER JOIN table b " +
		 "ON a.CTRL_ID = b.CTRL_ID " +
		 "WHERE AID = ?";

PreparedStatement prepstmt = connection.prepareStatement(prepSQL);
prepstmt.setString(1, aidstrd);
ResultSet admsql = prepstmt.executeQuery(); admsql.next();

(etc., etc.)

admsql.close();
selstmt.close();
connection.close();

If I move up connection.close, I get the Connection is closed statement,
otherwise I get exhausted result set. 
Any idea what gives?


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



 This e-mail is bound by the terms and conditions described at http://www.subexazure.com/mail-disclaimer.html



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message