1首先要有相應的jdbc
2.用tomcat的控制臺配置數據源。
3.到tomcat/conf下添加context。xml
內容如下:<Context>
??? <WatchedResource>WEB-INF/web.xml</WatchedResource>
??? <Resource??? name="jdbc/mysql"??? type="javax.sql.DataSource"??? password="sa"??? driverClassName="com.mysql.jdbc.Driver"??? maxIdle="2"??? maxWait="5000"??? username="root"??? url="jdbc:mysql://127.0.0.1/test"??? maxActive="4" />
</Context>
4。配置你相應的項目的web。xml添加:
<resource-ref>
? ?<description>DB Connection</description>
? ?<res-ref-name>jdbc/mysql</res-ref-name>
? ?<res-type>javax.sql.DataSource</res-type>
? ?<res-auth>Container</res-auth>? ?
? ?<res-sharing-scope>Shareable</res-sharing-scope>
? </resource-ref>
Ok!