Realization of Java connection pool

xiaoxiao2021-03-06  18

Can pass two ways

1 Add in

Add in the XML of Conf / Catalina / LocalHost

Add Web.xml in project web-infers

mssql javax.sql.datasource

2 is also added in in Server.xml

Add Web.xml in project web-infers

MSSQL Test App DB Connection JDBC / TESTDB Javax.sql .Datasource Container test:

<% @ 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 / TestDB"); Connection conn = ds.getConnection (); Statement stmt = conn.createStatement ( ); String strsql = "select * from authors"; ResultSet RS = stmt.executeQuery (strsql); while (rs.next ()) {Out.println (rs.getstring (1));}} Catch (Exception EX) {OUT.PRINT (EX); EX.PrintStackTrace ();}%>

in conclusion:

Carefully watch the documentation

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

New Post(0)