4.4. 添加 JDBC 数据源
配置 Tomcat 以使用 JDBC 数据源。
流程
-
打开部署的
/WEB-INF/web.xml文件进行编辑。 使用
resource-env-ref元素配置 JDBC 数据源,如下例所示,它使用 ajdbc/DsWebAppDB数据源:<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <resource-env-ref> <resource-env-ref-name>jdbc/DsWebAppDB</resource-env-ref-name> <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type> </resource-env-ref> </web-app>