Build a virtual site under Tomcat and configure the MySQL connection pool

xiaoxiao2021-03-06  59

The first installation is actually successful, written out for your reference.

Tomcat itself provides a good use of Web management tools. Let's use it to complete our work. First Open Tomcat / conf / Tomcat-users.xml Add the following code Save the restart Tomca service. Then access http: // localhost: 8080 / admin / you can enter the management page ... and then easy according to the page. Build your virtual site. Here I will not pay. The process of establishing a .xml file in Tomcat / Conf / Catalina / LocalHost / Under the virtual site name. Open this file, you can see it. All content such as: < Resource name = "eway365_mysql" type = "javax.sql.datasource" /> URL jdbc: mysql: //192.168.0.249: 3306 / Test password maxactive 20 maxwait -1 driverclassname com.mysql.jdbc.jdbc2 .opti OnAl.MysqlConnectionPoolDataSource username root maxIdle 20 < / value>

Where CONTEXT is to establish a site. DocBase indicates that the site where the site is located, the access path Workdir represents the working directory, because JSP is compiled into a Class file in the first runtime, and these compiler have existed .Resource It is to configure the connection pool ... JDBC: mysql: //192.168.0.249: 3306 / TEST IP address represents the IP of the database, 3306 is the default port of MySQL, Test is the database to connect. He added a sentence. To connect Mysql After installation MySQL, download MySQL's JDBC driver, you can get in MySQL's official website. ISERNAME Password nature is a username and password indicating the connection database. Enter the com.mysql.jdbc in .driverclassname according to the actual situation. JDBC2.OPTIONAL.MYSQLCONNECTIONPOOLDATASOURCE This string can be found in the JDBC driver. Maxactive indicates that the maximum number MaxIdle indicating the connection pool indicates the number of air closures of the connection pool (this is not clear, what does it mean, I know, I will reply me. Thank you) MaxWait indicates the time of the connection (-1 means waiting for it), and now you need to write a program to test it.

Built an index.jsp in your virtual site directory, the program content is as follows: <% @ Page ContentType = "text / html; charset = GBK"%> <% @ page import = "javax.naming. *, Java.sql *, javax.sql. * "%> <%

Context initcontext (); context envcontext = (context) INITCONTEXT.LOOKUP ("Java: / Comp / ENV");

DataSource DS = (DataSource) ENVCONTEXT.LOOKUP ("Eway365_Mysql"); // Here is the name connection conn = ds.getConnection (); out.println ("Connection pool configuration is successful!"); Conn.close () Out.println ("successfully connected!


");%>

Ok, I don't have any problems, I'm doing it ..........

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

New Post(0)