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 COMMON / LIB folder
2. Add the following code in the host domain in Tomcat 4.1
3. New folder "MyWeb", "MyWeb / Web-INF", "MyWeb / Web-INF", "MyWeb / Web-INF / CLASS" 4. "Web.xml" under Web-INF, and add the following? XML Version = "1.0" encoding = "ISO-8859-1">
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 initCtx = new initialContext (); if (initctx == null) throw new exception ("Boom - No Context"); DS = (DataSource) INitctX.lookup ("Java: Comp / Env / JDBC / MYDB"); if (DS ! = null) {con = ds.getConnection (); if (con! = null) {statement stmt = con.createstatement (); ResultSet = stmt.executeQuery ("Select * from authors"); rs.next () Val = rs.getstring ("au_id"); rs.close (); stmt.close (); }con.close ();}} catch (excetion ex) {system.out.println (ex.getMessage () );} Response.setContentType ("text / html"); PrintWriter out = response.getwriter (); out.println (""); Out.println ("" value " h1>); out.println (" body> "); out.println (" html> ");} } 6. Compile JDBCPoolServ.java gets JDBCPoolServ.class (Note Join Servlet.jar Pack), under "MyWeb / Web-Inf / Classes"
7. Start SQL Server2000
8. Start Tomcat
9. Browse http://127.0.0.0.1:8080/myweb/servlet/jdbcpoolserv
10. You can see "172-32-1176" in IE Note: If you are not working properly, check whether the above folder name, URL, and Java class name are uniform.
Bluepengui@china.com
Bluepenguin2003-2-11