Saturday, April 21, 2001 04:13 PM
Are you sure that you want to put the Connection in the session? If you have thousands of sessions existing at one time (not unreasonable for a 15-30 minute session expiration time on a high-traffic store), this would result in thousands of database connections. Also, why hold onto a database connection over the entire session life?
If you are persisting the shopping cart to a database, you only need a database connection for the time it takes to either read from or write to the database. Don't put the Connection and other JDBC objects into the session. You might, instead, want to keep a copy of the cart in the session, so that you don't need to do a database read on each page view. (Of course, this requires that you make sure that another session has not modified the cart since you retrieved it.)