JDBC Application Advanced (Overview) in Servlet

xiaoxiao2021-03-06  119

A dynamic website frequently acquires data from the database to form an HTML page. A database operation will occur at each request. But the connection database is a job that needs to consume a lot of time, as the request connection needs to establish communication, allocate resources, permission certification. These tasks are rarely completed in one or two seconds. So, create a connection, and then use this connection in subsequent queries to greatly improve performance. Because servlets can be kept in different requests, it is a direct solution with a database connection pool. Servlet resides in the process space of the server, which can be easily and persistently maintained. Next, we will introduce a complete connection pool implementation. In implementations, there is a connection pool manager management connection pool object, where each connection pool holds a set of database connection objects, which can be used for any servlet. First, the database connection pool DBConnectionPool provides the following methods: 1, get an open connection from the pool; 2. Return a connection back to the pool; 3. Release all resources when closed and close all the connections. In addition, DBConnectionPool also processes the connection failure, such as overs., communication failure, etc., and limits the number of connections in the pool according to a predefined parameter. Second, the manager class, DBConNetionManager, is packaged in a container, and manages all connecting pools. Its method has: 1. Call and register all JDBC drivers; 2. Create a DBConnectionPool object according to the parameter table; 3, map the name of the connection pool and the DBConnectionPool instance; .

转载请注明原文地址:https://www.9cbs.com/read-97542.html

New Post(0)