Ten steps to get the SQL Server2000 database connection pool in Tomcat4.1.18 servlet

zhaozj2021-02-16  62

Ten steps to get the SQL Server2000 database connection pool in Tomcat4.1.18 servlet

1. From http://www.microsoft.com/downloads/details.aspx?familyid=4f8f2f01-1ed7-4c4d-8f7b-3d47969e66ae&displaylang=en#filelist download "Microsoft SQL Server 2000 Driver for JDBC", installed, get MSBase .jar, mssqlserver.jar and msutil.jar three files, three files COPY to Tomcat 4.1 in the CommonLib folder 2. Add the following code in the host domain in the server.xml of Tomcat 4.1

Factory

Org.apache.commons.dbcp.basicDataSourceFactory

Maxactive

100

MaxIdle

30

Maxwait

10,000

Username

SA

Password

Your password

Driverclassname

com.microsoft.jdbc.sqlserver.sqlserverdriver

URL

JDBC: Microsoft: SQLServer: //127.0.0.1: 1433; DatabaseName = PUBS

3. New folder "MyWeb", "MyWebWeb-INF", "MyWebWeb-INF", "MyWebWeb-INF", "MyWebWeb-Inf", "MyWebWeb-INF" 4. Add the new file "Web.xml" under Web-INF, and add the following

"http://java.sun.com/dtd/web-app_2_3.dtd">

MY Web

Invoker

/ servlet / *

JDBC / MYDB

Javax.sql.datasource

Container

The preparation of the servlet program JDBCPoolServ.javaimport java.sql *;. Import javax.naming.Context; import javax.sql.DataSource; import javax.naming.InitialContext; import javax.servlet *;. Import javax.servlet.http *. ; import java.io. *; public class JDBCPoolServ extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {DataSource ds = null; Connection con = null; String val = "null", title = "JDBC Pooling test "; try {context = new initialContext (); if (initctX == null) throw new exception (" boom - no content "); DS = (DataSource) INITCTX.LOOKUP (" Java: comp / env / jdbc / mydb "); if (ds! = null) {con = ds.getConnection (); if (con! = null) {statement stmt = con.createstatement (); ResultSet RS = Stmt.executeQuery (" SELECT * from AUTHORS "); Rs.next (); val = rs.getstring (" au_id "); rs.close (); stmt.close ();} con.close ();} } Catch (exception ex) {system.out.println (ex.getMessage ());} response.setContentType ("text / html"); PrintWriter out = response.getwriter (); out.println (""); OUT .println (""); out.println (""); out.println (""); out.println (" valintln"); out.println ("" Out.println ("");}} 6. Compile JDBCPoolServ.java gets JDBCPOOLSERV.CLASS (Note Add Servlet.jar Pack), copy it to "MyWebWeb-Infclasses"

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

New Post(0)