JSP's SQL Server2000 Database Connection Pool Configuration

xiaoxiao2021-03-14  214

JSP's SQL Server2000 Database Connection Environment: 1. Database: Microsoft SQL Server 20002. Database Driver: Net.SourceForge.jtds.jdbc.driverjndi (Java Naming and Directory Interface Overview: Tomcat4 (5) provides A JNDI-INITIALCONTEXT implementation instance compatible with the Java Enterprise Edition application service. Its initial data is set in the $ catalina_home / conf / server.xml file and may be referenced by the following elements in the web application environment description (/Web-inf/web.xml): 1) - Environment Inlet, set how the application is operated. 2) - Resource parameters, usually database drivers, JavaMail session, custom class, etc. 3) - The resource-ref variables are used to simplify settings that do not require authentication information in Servlet 2.4. INITIALCONTEXT is set when the web application is initialized to support web application components. All portions and resources are placed in Java: Comp / ENV segment in JNDI namespace. Click on the following URL to get more information: 1) Java Naming and Directory Interface 2) J2EE Platform Description Set JNDI Resource Settings JNDI Resources To be in $ Catalina_Home / Conf / Server.xml file Use the following markers: 1) - Set the names and values ​​of the domain variable JNDI INITIALCONTEXT entry (with the equivalent). 2) - Set the name and type of the resources available to the application (the same above "Resource-Ref> equivalent). 3) - Set the name of the Java resource factory or the JavaBeaN property that will be used. 4) - Add a link to the Global JNDI environment (JNDI Context). These markers must be placed between and (for special web applications) or and . In addition, the names and values ​​set in the web application design (/ web-inf / web.xml) are also set in the initial context, when the element value is allowed Reset initial value. Global variables can be set in in child elements. Database connection pool overview: Database connection is a key limited expensive resource, which is particularly highlighted in multi-user web applications. The management of database connections can significantly affect the scalability and robustness of the entire application, affecting the performance indicators of the program. The database connection pool is proposed for this issue.

The database connection pool is responsible for assigning, managing, and releasing the database connection, which allows the application to reuse an existing database connection, and then re-establish a database connection to the idle time exceeding the maximum idle time to avoid because there is no release database connection. Indicated database connections. This technology can significantly improve the performance of database operations. Database connection pool When you initialize a certain number of database connections to the connection pool, the number of these database connections is set by the minimum database connection. Whether these database connections are used, the connection pool will always guarantee that there are at least so many connections. The maximum number of database connections for the connection pool limits the maximum number of connections that can be occupied. When the application of the application exceeds the maximum number of connections to the connection pool, these requests will be added to the waiting queue. The minimum connection of the database connection pool and the maximum number of connections are set to take into account the following factors: 1) The minimum connection is the database connection that the connection pool has always been maintained, so if the application is not used in the database connection, will There is a lot of database connection resources; 2) The maximum number of connections is the maximum number of connections for the connection pool. If the database connection request exceeds this, the rear database connection request will be added to the waiting queue, which will affect Database operation. 3) If the minimum number of connections is too large to the maximum number of connections, the first connection request will be profitable, and then the connection request for the minimum connection number is equivalent to establishing a new database connection. However, these database connections larger than the minimum connection number will not be released immediately, which will be released in the connection pool to be reused or idle. Configuring the Tomcat database connection pool premise: In the directory (only here). Use it because Microsoft's Java SQL Server driver does not support secondary queries, you can get to the Internet. It is currently using JTDS-0.6.jar. Setting up a database connection pool in $ catalina_home / conf / server.xml: The following is the code configured, must be placed between and .

maxactive 100 maxIdle - maximum number of idle db connect t p} -> 30 maxwait 10000 < / parameter> removeabandones true removeAbandonedTimeout <-! Use the removeAbandonedTimeout parameter to set the number of seconds a DB connection has been idle before it is considered abandoned -.> 60 Logabandoned

False factory org.apache.commons.dbcp.basicDataSourceFactory iorishinier password mypasswd driverclassname net.sourceforge.jtds.jdbc.driver < / value> URL jdbc: jtds: sqlserver: //127.127.127.127: 1433 / northwind < / parameter> The following is a number of parameters: 1: 1 Path Specifies the path, which is set to the QUALITY directory under $ catalina_home / webApps; 2) DocBase file root directory. 3) RELOADER is recompiled when the web is updated. 4) The maximum number of database connections for the MaxActive connection pool. Set to 0 means unlimited. 5) The maximum idle time for the MaxIdle database connection. More than this idle time, the database connection will be marked as unavailable and then released. Set to 0 means unlimited. 6) MaxWait builds a maximum connection wait time. If you exceed this time will receive an exception. Set to -1 means unlimited. 7) Removeabandoned recycles abandoned (generally forgotting the release) database connection to the connection pool. 8) RemoveabandONEDTIMEOUT Database Connections After the connection is not considered to be abandoned and the connection pool is retracted. 9) logabandoned will be recorded in the logged database. 10) DriverclassName JDBC driver. 11) URL database connection string Set the referenced resource in $ CATALINA_HOME / WebApps / Quality / Web-INF / Web.xml: The following is the configuration code, must be placed in and .

ConnectDB test jdbc / connectiondb javax.sql .Datasource Container The following is the necessary description: 1) Description is referenced Description of resources. 2) RES-REF-NAME resource name. See the 3) RES-TYPE resource type. See the Using resources in JSP: This is in a certain level directory under $ catalina_home / webapps / Quality JSP page file part code: <% @ page contenttype = "text / html; charset = GBK"%> <% @ page errorpage = "error.jsp"%> <% @ Page Import = "javax.naming. *" %> <% @ page import = "javax.sql. *"%> <% @ Page Import = "java.sql. *"%> <% ......... ..................................

// Database Operation Context CTX = NULL; Connection CNN = NULL; Statement Stmt = Null; ResultSet RS = NULL; TRY {CTX = New InitialContext (); if (CTX == Null) Throw new Exception ("No Match Environment" ); DataSource DS = (Datasource) CTX.lookup ("java: comp / env / jdbc / connection); if (ds == null) throw new exception (" No matching database "); cnn = ds.getConnection () ; Stmt = cnn.createstatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_read_only); RS = Stmt.executeQuery ("SELECT * from Table1");

.................. ................

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

New Post(0)