Web interface configuration Tomcat connection pool - I have a little personal experience

zhaozj2021-02-16  26

I think the simplest method, Tomcat4.1.29 is 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 Source

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

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 command changes button on 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-27618.html

New Post(0)