|
PooledConnection is an interface, and can't actually be used (unless you get it from some other object). The only implementing class listed in the API is a bit daunting, and I'm not really sure what it's for.
What I posted wasn't a pool, but a wrapper around a Connection. If you were using a pool, you'd get the connection from the pool at "// Create Connection here." The pool would handle the bookeeping for the connections, such as keeping them open to increase efficency.
You wouldn't want to keep a single connection open for a page, as it wouldn't be thread-safe, and a second query might go through before you've finish processing the results of the first. You either need to queue the requests, or create seperate connections (I'd suggest the latter).
Basically, the ideal situation is that you have this abstract pool of database connections. They're established, so there isn't any overhead of making a new connection for each request. When a page or object needs to query the DB, it requests one of these connections from the pool. When it's done with the query, it hands it back. You've achieved the same goal as keeping an open connection in each page, but you've simplified your life and written better code.
|