【发布时间】:2012-07-17 19:24:48
【问题描述】:
我在Tomcat的context.xml中添加了如下标签:
<Resource name="jdbc/PollDatasource" auth="Container" type="javax.sql.DataSource"
driverClassName="org.apache.derby.jdbc.ClientDriver" url="jdbc:derby://localhost:1527/poll_database;create=true"
username="suhail" password="suhail" maxActive="20" maxIdle="10" maxWait="-1" />
当服务器启动并部署应用程序时,会读取上面的标签。我还在我的项目的web.xml 中添加了以下内容:
<resource-ref>
<description>my connection</description>
<res-ref-name>jdbc/PollDatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
上面的标签是什么意思?
因为当我写这样的语句时:
DataSource ds = (DataSource)envContext.lookup("jdbc/PollDatasource")
不是直接查看服务器的context.xml吗?我知道我错了。在这种情况下,请帮助我理解 resource-ref 标签在 web.xml 中的含义是什么?
【问题讨论】:
标签: java database tomcat jdbc datasource