Web Hosting Java, JSP, Tomcat 6, J2EE, Servlets, Struts, Jboss
Comcast webspace - JavaSercer Pages javax.sql.ConnectionPoolDataSource A DataSource implementation that provides
January 22, 2007 on 6:13 pm | In Java |JavaSercer Pages javax.sql.ConnectionPoolDataSource A DataSource implementation that provides pooling capabilities uses a class that implements the ConnectionPoolDataSource interface. A ConnectionPoolDataSource is a factory for PooledConnection objects. Figure 17.1 outlines how an application uses implementations of these interfaces to obtain a pooled connection and how to return that connection to the pool. Figure 17.1. Application using a JDBC 2.0 connection pool The application calls the DataSource getConnection( ) method. The DataSource looks for an available PooledConnection object in its pool. If it doesn’t find one, it uses its ConnectionPoolDataSource object to create a new one. It then calls the getConnection( ) method on the PooledConnection object and returns the Connection object associated with the PooledConnection. The application uses the Connection, and calls its close( ) method when it’s done. This results in a notification event being sent to the DataSource, which puts the corresponding PooledConnection object back in the pool. If you would like to learn more about the JDBC 2.0 connection pool model, you can download the JDBC 2.0 Optional Package specification from http://java.sun.com/products/jdbc/. The real beauty of these interfaces is that the application doesn’t have to be aware that it’s using a connection pool. All configuration data, such as which JDBC driver and JDBC URL to use, the initial and maximum numbers of pooled connections, and the database account name and password, can be set by a server administrator. The completely configured DataSource object is registered as a JNDI resource, and the application can obtain a reference to it with the following code: Context ctx = new InitialContext( ); DataSource ds = (DataSource) ctx.lookup(”jdbc/EmployeeDB”); It then gets a Connection, uses it, and returns it with the following code: Connection conn = ds.getConnection( ); // Uses the Connection conn.close( ); // Returns the Connection to the pool By implementing these JDBC 2.0 interfaces, JDBC driver and middleware vendors can offer portable connection pooling implementations. Sun’s JDBC driver list contains roughly ten different companies that claim to either offer implementations of connection pools today or have announced products to be delivered during 2000. 17.1.2 Making a JDBC 1.0 Connection Pool Behave as a JDBC 2.0 Connection Pool If you can’t find a JDBC 2.0 connection pool implementation for your database, there are plenty of implementations based on JDBC 1.0 available. I describe one in an article I wrote for the Web Developer’s Journal, titled “Improved Performance With a Connection Pool,” available at http://www.webdevelopersjournal.com/columns/connection_pool.html. Another is the DBConnectionBroker , available at http://www.javaexchange.com. It’s easy to develop a couple of wrapper classes for one of these implementations so that it can be used in place of a JDBC 2.0 connection pool implementation. This way, you can switch out the JDBC 1.0 pool with a JDBC 2.0 pool when one becomes available from your database vendor or a third party. page 237
Hint: This post is supported by Gama web hosting php mysql provider
No Comments yet
Sorry, the comment form is closed at this time.
...I
just wanted to take the time to say "Thank you!" for our new webmail
system. It's great! Thanks for taking such good care of us.
Thanks
for helping me out. Just for the record, Webhostingjava.net has been a great
web host! So far your support and handling of questions has far
exceeded that of a "larger web hosting company".
I
would like to thank you for helping me with my domain...You have
shown me great patience and professionalism. I would not hesitate to
recommend you to my clients.