Cory L Hubert wrote:
>
> Ok. I am on a roll now. I am trying to setup a Connection Pool. I have
> a few samples. But I don't know where to put it in my project. Should I
> put it in the Beans? Or should I just make one connectionpool jsp file and
> include it in all the pages?
>
> What is the best way? I know this is an opened end question but, I'd like
> to hear a few suggestions.
We have also written a simple singleton ConnectionGenerator class that
has static poolCheckout(...) and poolCheckin(Connection) methods. These
methods are used
inside our *bean* code whenever a db connection in needed. This is done
because
you want to be sure to check the Connection back into a pool regardless
of whether
an exception occurred in your code or not, so you need a try/finally
combo.
We also use this combo to implement transaction rollback when
multi-statement
transactions are used.
For example:
boolean autoCommit = false;
boolean committed = false;
Connection c = ConnectionGenerator.poolCheckout();
Statement s = null;
try {
// do some stuff that could possibly throw an exception.
s = c.createStatement();
s.executeUpdate("UPDATE x SET q=5");
s.commit();
s.close();
committed = true;
s = null;
}
finally {
if( s != null ) try {s.close();} catch(SQLException ignore1) { }
if(!committed ) try {c.rollback();} catch(SQLException ignore2)
{ }
ConnectionGenerator.poolCheckin(c);
}
I really don't think you'd want to implement this sort of code in a
.jsp...
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html