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.