Web interface configuration Tomcat connection pool

xiaoxiao2021-03-06  64

Take Tomcat4.1.29 as an example

1. Put the database driver file COPY to Tomcat Your WebApp WEB-INF / LIB folder

2, start Tomcat, enter the administrator interface (Tomcat homepage has a link, if you don't know the password, open the Tomcat-users.xml file under the Tomcat file, use notepad to open, there is admin user Name and password, the default password for admin is empty)

3, click on the left column Tomcat Server >>> Service >>> Host >>> Your WebApp's Context >>> Resources >>> Data Sources

4. Select Create New Data Source >>> and configure DataSource information in the Data Source Actions drop-down box in the right column.

As to MSSQL Example: JNDI Name: jdbc / mssql Data Source URL: jdbc: microsoft: sqlserver: //192.168.0.52: 1433; databaseName = abuJDBC Driver Class: com.microsoft.jdbc.sqlserver.SQLServerDriverUser Name: abuPassword: Abumax. Active Connections: 2max. Wait for connection: 5000Validation query: / / Can not fill

5. Click the Save button >>> Click on the top of the page.

6, restart the service, enter the following code in the test page

<% @ page import = "java.sql. *"%> <% @ page import = "javax.sql. *"%> <% @ page import = "javax.naming. *"%> <% datasource ds = null; try {InitialContext ctx = new InitialContext (); ds = (DataSource) ctx.lookup ( "java: comp / env / jdbc / mssql"); Connection conn = ds.getConnection (); Statement stmt = conn.createStatement ( String strsql = "select * from ttt"; ResultSet RS = stmt.executeQuery (strsql); while (rs.next ()) {system.out.println (rs.getstring (1));}} catch (Exception EX) {EX.PrintStackTrace ();}%>

7. At the console should be able to see the printed thing.

I hope to bring you a little help.

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

New Post(0)