一、Tomcat中的Server.xml配置
<Context docBase="Olympic" path="/Olympic" reloadable="true" source="org.eclipse.jst.jee.server:Olympic"> <Logger className="org.apache.catalina.logger.FileLogger" prefix="localhost_MSSQL_Log." suffix=".txt" timestamp="true"/> <Resource name="jdbc/olympic" auth="Container" type="javax.sql.DataSource" factory="org.apache.commons.dbcp.BasicDataSourceFactory" maxActive="5" minIdle="2" maxWait="5" username="sa" password="sa" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" url="jdbc:microsoft:sqlserver://127.0.0.1:1433;databasename=olympic" /> </Context> |
此Context放到Server.xml文件的Host中
二、在WEB应用中引用数据源
<resource-ref> <description>Movie Datasource</description> <res-ref-name>jdbc/olympic</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> |
将此内容放到WEB.xml文件中