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 number of dB connections in pool Make sure you configure your mysqld max_connections large enough to handle all of your db connections Set to 0 for no limit -.>
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, replace the original content with the following code
XML Version = "1.0" Encoding = "ISO-8859-1">
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 RST = Stmt.executeQuery ("Select * from Orders"); 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> 'www.knowsky.com
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.