1.把驱动拷贝到%TOMCAT_HOME%/common/lib目录下
2.新建数据库表,并向表中添加记录
1   use  test;
2   create   table  testdata (
3         id  int   not   null  auto_increment  primary   key ,
4         foo  varchar ( 25 ), 
5         bar  int );
6 insert   into  testdata  values ( null ' hello ' 12345 );
7

3.在%TOMCAT_HOME%/config/server.xml文件中加入如下一段配置信息(在之前)
 
 1         
 2     
 3 < Context  path ="/WS4Motel"  docBase ="WS4Motel"
 4         debug ="5"  reloadable ="true"  crossContext ="true" >
 5
 6     
10
11     
15
16     
20
21     
22
23     
27     
28     
33
34    < Resource  name ="jdbc/WS4Motel"  auth ="Container"  type ="javax.sql.DataSource"
35                maxActive ="100"  maxIdle ="30"  maxWait ="10000"
36                username ="root"  password ="83072674"  driverClassName ="com.mysql.jdbc.Driver"
37                url ="jdbc:mysql://localhost:3306/test?autoReconnect=true" />
38
39 Context >
40         
41
 4.写个简单程序测试下:
1 <% @ taglib uri = " [url]http://java.sun.com/jsp/jstl/sql[/url] "  prefix = " sql "   %>
 2 <% @ taglib uri = " [url]http://java.sun.com/jsp/jstl/core[/url] "  prefix = " c "   %>
 3
 4 < sql:query var = " rs "  dataSource = " jdbc/TestDB " >
 5 select id, foo, bar from testdata
 6 sql:query >
 7
 8 < html >
 9    < head >
10      < title > DB Test title >
11    head >
12    < body >
13
14    < h2 > Results h2 >
15   
16 < c:forEach var = " row "  items = " ${rs.rows} " >
17     Foo $ {row.foo} < br />
18     Bar $ {row.bar} < br />
19 c:forEach >
20
21    body >
22 html >
23