Wrapping JDBC Objects
by, 05-25-2011 at 10:55 AM (3612 Views)
In Glassfish connection pool has a property called "Wrap JDBC Objects" which can have value true or false. You may define it in domain.xml file.
This property is defined as: "When set to true, application will get wrapped jdbc objects for Statement, PreparedStatement, CallableStatement, ResultSet, DatabaseMetaData".
If you follow JDBC specifications, you will be see that obtaining connection using DataSource.getConnection() or other objects like statement, preparedStatement.getConnection() should be same. Do note its not the same if you use Glasshfish application server. GlassFish does not wrap others like statement, preparedStatement. Because of this, statement.getConnection() will return the physical connection rather than the one provided by GlassFish. This means that you might be using physical connection rather than connection from connection pool.
In the above example, you close the physical connection and not the logical connection, therefore connections are not returned to pool.Java Code:stat = rs.getStatement(); con = stat.getConnection();[/b] rs.close(); rs=null; stat.close() ; stat = null; con.setAutoCommit(true); con.close();
Following code will also give you a physical connection and hence will cause connection leak.
wrap-jdbc-objects=true will make sure that statement.getConnection will be the same as DataSource.getConnection().Java Code:com.sun.appserv.jdbc.DataSource ds = ......... Connection con = ds. getConnection(); physicalCon = ds.getConnection(con);
You may define this property via asadmin command. For instance:
I hope you find this useful.Java Code:asadmin list "*DerbyPool*" domain.resources.jdbc-connection-pool.DerbyPool server.resources.jdbc-connection-pool.DerbyPool asadmin get domain.resources.jdbc-connection-pool.DerbyPool.* ... ... domain.resources.jdbc-connection-pool.DerbyPool.validate-atmost-once-period-in-seconds = 0 ... domain.resources.jdbc-connection-pool.DerbyPool.wrap-jdbc-objects = false asadmin set domain.resources.jdbc-connection-pool.DerbyPool.wrap-jdbc-objects=true domain.resources.jdbc-connection-pool.DerbyPool.wrap-jdbc-objects = true