============================================================================================================================================================================================================= ============================= 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 three files for msbase.jar, mssqlser.jar and msutil.jar, three files Copy to Tomcat 4.1 under the Common / Lib folder
2. Add the following code in the host domain in Tomcat 4.1
4. New file "Web.xml" under Web-INF, and add the following XML Version = "1.0" Encoding = "ISO-8859-1"?>
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.
============================================================================================================================================================================================================= ================
Tomcat5 MSSQL Server 2000 Database Connection Pool Configuration Tour Rautinee Original (Participation: 43, Expert Score: 10) Published: 2004-2-20 11:00 am Version: 1.0
Tomcat believes that everyone is already familiar. As a free and powerful Java Web Server, I got a lot of Java enthusiasts, the latest version of Tomcat5 support servlet2.4 and jsp2.0, today I will use Tomcat5 and MS SQLServer 000 Start the database connection pool configuration together. Need to prepare 1, JDK I use version 1.4.012, Tomcat 5 I use 5.0.16 version download address: http://jakarta.apache.org/site/binindex.cgi3, mssql server 2000 database 4, MSSQL Server 2000 official JDBC Driver, you can download Microsoft's official website free download
After installation of the software installed, I will enter the configuration.
First, find the JDBC installation directory, put the msbase.jar and mssqlser.jar below the lib directory, Msutil.jar three files Copy to $ catalina_home / common / lib / ($ CATALINA_HOME representative is your Tomcat5 installation directory)
Second, use the text editor, I am using editplus to open the $ catalina_home / conf / server.xml file using EditPlus, find the following, paste the following code into the file
<-!.. Maximum time to wait for a dB connection to become availablein ms, in this example 10 seconds An Exception is thrown ifthis timeout is exceeded Set to -1 to wait indefinitely .-->
Note: The password of the SA of my local database is empty, the database is Northwind, my directory name DBTEST, his directory is d: / Rautinee Work / DB / Open the Web.xml file below DBTest, with the following code Replace the original content
XML Version = "1.0" Encoding = "ISO-8859-1">
OK, the configuration is complete, the following work is to write two files to test, whether the connection is successful.
Here I use http://jakarta.apache.org above example
The first is the bean file
Package foo;
Import javax.naming. *; import javax.sql. *; import java.sql. *;
Public class dbtest {
String foo = "not connection"; int BAR = -1;
Public void init () {Try {context ctx = new initialcontext (); if (ctx == null) throw new exception ("Boom - no context");
DataSource DS = (Datasource) CTX.lookup ("Java: Comp / Env / JDBC / TESTDB");
IF (ds! = null) {connection conn = ds.getConnection ();
IF (conn! = null) {foo = "got connection" conn.tostring (); statement stmt = conn.createstatement (); resultset = stmt.executeQuery ("Select * from orderers"); if (Rst.next ()) {foo = Rst.getstring ("Customerid"); bar = Rst.Getint ("ORDERID");} CONN.CLOSE ();}}} Catch (Exception E) {E.PrintStackTrace ();}}
Public string getfoo () {return foo;} public int getbar () {return bar;}}
Then INDEX.JSP file
body> html>
Compile operation, if you don't accident, you should retrieve a record.
My IE shows MS SQL Server 2000 Java Search Resultsfoo Vinetbar 10248
OK, the formulation is successful!
Reference document: http://jakarta.apache.org/tomcat/tomcat-5.0-doc/jndi-datasource-examples-howto.html Above there is mysql and oracle8i connection tutorial, interested friends can go to see. ============================================================================================================================================================================================================= ==================================== BTW: Tomcat5 is likely to have problems, and the solution sees the http: // blog in my blog. 9cbs.net/neetsniffert/archive/2004/10/14/135817.aspx