Database Connection Buffer Pool

Source: Internet
Author: User

A database buffer pool refers to the physical connections of databases cached in the memory space. These database connections can be reused. The database buffer pool is very important for improving the performance of Java database applications, especially when the Java database application runs in the middle layer server environment.
The data buffer pool exists in the intermediate layer server environment and can be called by different Java applications. The javax. SQL. RowSet package adds support for the buffer data source. This allows you to regard the database connection of the buffer pool as a real data source service. The RowSet package provides several interfaces to process the database buffer pool. The main interfaces are:
1. DataSource interface: the Instance Object of the DataSource interface represents the buffer data source service that exists on the intermediate layer server. It can be used to return existing database connections in the database buffer pool. The instance object of the DataSource interface is actually a provider of a JNDI service. before using it, the JNDI service object must be registered in the intermediate layer server environment and bound with a service name before it can be called by other Java applications.
2. ConnectionPoolDataSource interface: this interface can be used to create a physical connection to the database buffered in the buffer pool. It may be called by the Instance Object of the DataSource interface.
3. PooledConnection interface: this interface represents the buffered database Connection. It defines a getConnection () method that can return the Instance Object of the java. SQL. Connection interface.
The following JSP code snippet provides a simple and incomplete example of how to use the class and interface defined by the RowSet package to operate the database buffer pool.
Example
<%
Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx. lookup ("jdbc/EmployeeDB ");
// First get a Connection. Connection pooling is done
// Internally by the DataSource object.
Connection con = ds. getConnection (jdbc/webDatabase "" sa "");
// Do all the work as a single transaction (optional ).
Con. setAutoCommit (false );
// The actual work (queries and updates) wocould go here.
// Work is done using standard JDBC code as defined in
// Rest of the jdbc api.
// Commit the transaction.
Con. commit ();
// Close the connection. This returns the underlying physical
// Database connection to the pool.
Con. close ();
%>
The running mechanism of the preceding JSP code segment is as follows:
???? 1. First, the program code obtains the initialized JNDI environment and calls the Context. lookup () method to obtain a DataSource object from the JNDI service provider.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.