Search code examples
javajakarta-eejdbcjtdsapache-commons-dbcp

JTDS driver - Connection pooling vs Connection pool


I have been somewhat away from Java EE for a while, but I have a basic idea of all this stuff.

I am reading the JTDS docs here:

http://jtds.sourceforge.net/features.html

It says it provides statement pooling, and connection pooling, but does not provide a connection pool implementation.

  1. Provided that the JTDS driver itself provides connection pooling, then why do I need a connection pool (like DBCP) on top it?
  2. In other words, what is the difference between that connection pooling provided by JTDS, and a full-blown connection pool implementation (in the sense of this JTDS documentation page) on top of it?
  3. Also, what's the difference between statement and connection pooling (as mentioned there on this JTDS doc page)?

Feel free to add more details to your answer
(whatever you find important; things I didn't ask explicitly about)
as I am quite confused with this.


Solution

  • As far as I can tell from the API documentation, they mean that jTDS provides a javax.sql.PooledConnection and a javax.sql.ConnectionPoolDataSource implementation. These classes are to be used by a connection pool of - for example - a Java EE application server, and are not a connection pool itself.

    The ConnectionPoolDataSource creates PooledConnection objects, or in other words it is the data source for a connection pool. The PooledConnection is the handle for the physical connection, and is held within the connection pool. When a user asks for a connection from the pool, the connection pool moves the PooledConnection from the 'available' to the 'in use' list, and obtains a logical java.sql.Connection from the PooledConnection. This logical connection is what is handed to the user.

    The PooledConnection can be use by the connection pool to monitor the logical connection. For example to return the PooledConnection to 'available' when close() is called, or forcibly revoke and invalidate the logical connection (eg if it is in use too long).

    So jTDS does not have a connection pool implementation itself, but it has the support for a connection pool. It is unfortunate that the wording in the JDBC specification is so confusing.

    I have a more detailed answer on this subject on a similar question.