David said:
It occurred to me later, if the Connection is from a connection pool,
and isn't really closed at that point of calling "close()" in user
code, will those resources still be automatically closed, or would
they be closed only if the actual Connection is closed?
More quotes:
<quote>
In a DataSource implementation that includes connection pooling, a great
deal
happens behind the scenes. In such an implementation, the following are
true:
â– The DataSource implementation includes an implementation-specific
connection pooling module that manages a cache of PooledConnection objects.
The DataSource object is typically implemented by the application server
as a
layer on top of the driver’s implementations of the
ConnectionPoolDataSource and PooledConnection interfaces.
â– The DataSource.getConnection method calls
PooledConnection.getConnection to get a logical handle to an underlying
physical connection. The overhead of setting up a new physical connection is
incurred only if there are no existing connections available in the
connection pool.
When a new physical connection is needed, the connection pool manager
will call
the ConnectionPoolDataSource method getPooledConnection to create
one. The work to manage the physical connection is delegated to the
PooledConnection object.
â– The Connection.close method closes the logical handle, but the physical
connection is maintained. The connection pool manager is notified that the
underlying PooledConnection object is now available for reuse. If the
application attempts to reuse the logical handle, the Connection
implementation
throws an SQLException.
â– A single physical PooledConnection object may generate many logical
Connection objects during its lifetime. For a given PooledConnection object,
only the most recently produced logical Connection object will be valid. Any
previously existing Connection object is automatically closed when the
associated
PooledConnection.getConnection method is called. Listeners (connection
pool managers) are not notified in this case.
This gives the application server a way to take a connection away from a
client.
This is an unlikely scenario but may be useful if the application server
is trying
to force an orderly shutdown.
â– A connection pool manager shuts down a physical connection by calling the
method PooledConnection.close. This method is typically called only in
certain circumstances: when the application server is undergoing an orderly
shutdown, when the connection cache is being re initialized, or when the
application server receives an event indicating that an unrecoverable
error has
occurred on the connection.
</quote>
<quote>
11.6.2 Closing a Pooled Statement
An application closes a pooled statement exactly the same way it closes
a non pooled
statement. Whether it is pooled or not, a statement that has been closed
is no longer
available for use by the application, and an attempt to reuse it will
cause an
exception to be thrown.
The following methods can close a pooled statement:
■Statement.close — called by an application; if the statement is being
pooled,
closes the logical statement used by the application but does not close the
physical statement being pooled
■Connection.close — called by an application
■Non pooled connection — closes the physical connection and all statements
created by that connection. This is necessary because the garbage collection
mechanism is unable to detect when externally managed resources can be
released.
■Pooled connection — closes the logical connection and the logical
statements it
returned but leaves open the underlying PooledConnection object and any
associated pooled statements
■PooledConnection.close — called by the connection pool manager to close
the physical connection and the associated physical statements being
pooled by
the PooledConnection object
An application cannot directly close a physical statement that is being
pooled;
instead, this is done by the connection pool manager. The method
PooledConnection.close closes the connection and all of the statements
open on
a given connection, which releases the resources associated with those
statements.
</quote>
I think it can be summarized to:
close of logical connection => close of logical statement
close of physical connection => close of physical statement
Arne