新建工程testmydb;
在$tomcat\conf\Catalina\localhost下建立testmydb.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
        
<Resource name="jdbc/testmydb" type="javax.sql.DataSource" 
        password
="******" 
        driverClassName
="com.microsoft.jdbc.sqlserver.SQLServerDriver"
        maxIdle
="2"
        maxWait
="5000"
        username
="babyuser"
        url
="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=bbs"
        maxActive
="4"/>
</Context>
在$tomcat\webapps\testmydb\WEB-INF\下新建web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version
="2.4">

  
<display-name>Tomcat Documentation</display-name>
  
<description>
     Tomcat Documentation.
  
</description>
    
<resource-ref>
    
<description>sqlserverDB Connection</description>
    
<res-ref-name>jdbc/testmydb</res-ref-name>
    
<res-type>javax.sql.DataSource</res-type>
    
<res-auth>Container</res-auth>
    
</resource-ref>

</web-app>
在$tomcat\webapps\quickstart\目錄下新建index.jsp文件
<%@ page contentType="text/html;charset=gb2312"%>   
<%@ page import="java.sql.*"%> 
<%@ page import="javax.naming.*" %>
<%@ page import="javax.sql.*" %>
<%!
public static String getGBString(String src) {
        try {
            return 
new String(src.getBytes("ISO-8859-1"), "gb2312");
        } catch (java.io.UnsupportedEncodingException e) {
            return 
null;
        }
    }
%>
<html><head><title>JDBC Test</title></head><body>
<%
Connection conn
=null;
Statement stmt
=null;
ResultSet rs
=null;
ResultSetMetaData md
=null;
try
{Context initCtx
=new InitialContext();
DataSource ds
=(DataSource)initCtx.lookup("java:comp/env/jdbc/quickstart");
if(ds!=null)
{
out.println(
"已經(jīng)獲得DataSource");
//out.println(ds.toString());
conn
=ds.getConnection();
stmt
=conn.createStatement();
out.println(
"aa");
rs
=stmt.executeQuery("SELECT TOP 5 * FROM Dv_Topic WHERE (Boardid = 37) AND (istop = 1)");
md
=rs.getMetaData();
out.println(
"<table border=1>");
out.println(
"<tr>");
for(int i=0;i<md.getColumnCount();i++)
{
out.println(
"<td>"+md.getColumnName(i+1)+"</td>");
}
while(rs.next())
{
out.println(
"<tr>");
out.println(
"<td>"+rs.getString(1)+"</td>");
out.println(
"<td>"+getGBString(rs.getString(2))+"</td>");
out.println(
"<td>"+rs.getString(3)+"</td>");
out.println(
"<td>"+rs.getString(4)+"</td>");
out.println(
"</tr>");
}
out.println(
"</table>");
conn.close();
}
}
catch(Exception e)
{
out.println(e.toString());
System.out.println(e.toString());
}
%>
</body></html>

點(diǎn)擊http://localhost:8080/testmydb/鏈接成功!會(huì)出現(xiàn)
已經(jīng)獲得DataSource aa
TopicID Title Boardid PollID LockTopic Child PostUsername PostUserid DateAndTime hits Expression VoteTotal LastPost LastPostTime istop isvote isbest PostTable SmsUserList IsSmsTopic LastSmsTime TopicMode Mode GetMoney UseTools GetMoneyType HideName
201314 親吻北京!——我們偉大的祖國(guó)! 37 0

當(dāng)然tomcat連接需要sql2000的3個(gè)驅(qū)動(dòng)文件msutil.jar、msbase.jar、mssqlserver.jar
sql2000需要升級(jí)到sp4;