An easy to use and relisable connection connection pool.
I actually used the source code with a lot of success :
 http://webdevelopersjournal.com/columns/connection_pool.html

Philippe

= = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Philippe Bertramo
World Customs Organization
Brussels - Belgium


-----Original Message-----
From: Jonathan Silvergran, SM3OJR [mailto:[EMAIL PROTECTED]]
Sent: vendredi 5 janvier 2001 15:11
To: [EMAIL PROTECTED]
Subject: Connections bound to the session - comments wanted


Greetings,

In a web ap consisting of a number of servlets, I have a "WelcomeServlet"
which is the first servlet called for each session. In this servlet, I
create a JDBC connection that I store in the session.

I have created a method for executing SELECT queries that looks like this:

// Set autoCommit to false in the query call for manual transactions
public ResultSet runQuery(boolean autoCommit, String qString) {

  Connection con = (Connection)session.getValue("connection"); // Get the
conn from session

    try {

      if ( con != null ) {

        if ( !autoCommit )
          con.setAutoCommit(false);
        else
          con.setAutoCommit(true);

        Statement statement = con.createStatement();
        rs = statement.executeQuery(qString);

        session.putValue("connection", con); // Write the conn back to the
session in
                                             // case the AutoCommit status
has changed
    }

    catch... etc

    return rs // returns the ResultSet
}


First, is this way of handling connections recommendable? My application
will not be used by that many, especially not at the same time. I know that
a ConnectionPool is more appropriate, but I don't have the time to learn how
to do it. (The Hunter's servlet book said it was fairly complicated..  :)

Second, I have a problem with the AutoCommit setting. If I don't touch it at
all (ie remarking the if clause in the code above) it works great. On the
other hand, if I put  setAutoCommit(true)  and try to execute a query, an
empty ResultSet is returned. Why? I can't see the differenct between turning
AutoCommit on and doing nothing at all, which, AFAIK, actually IS AutoCommit
on...

Any comments appreciated. Thanks!

/Jon
Jon, sm3ojr

European distributor of the following products:

* TR Logging Program (by N6TR)
* WJ2O Master QSO Logging Program (by WJ2O)
* RTTY (by WF1B)

---
Jonit Software, Box 178, SE-83122  OSTERSUND, Sweden
Phone: +46-63-57 21 21
Fax / 24h order: +46-63-57 21 22
Mobile: +46-70-569 21 21
E-mail: [EMAIL PROTECTED]
URL: http://www.jonit.com
ICQ: 7319834
---

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to