Java Reference
In-Depth Information
Example
<resource-ref>
<res-ref-name>jdbc/Finances</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
7.12.3
Mapping the Resource Reference onto a Real Resource
First create folder
META-INF
alongside
WEB-INF
and then create folder
context.
xml
inside
META-INF.
Within
context.xml
, create a
<Context>
tag and place within
it a
<Resource>
tag. The
<Resource>
tag will have eight attributes:
name
(of the specifi c resource);
type
(which will be
javax.sql.DataSource
);
auth
(again specifying the Tomcat container, as in the
web.xml
fi le);
username
;
password
;
driverClassName
(the MySQL driver, in this case);
factory
(a fully qualifi ed reference to the
DataSourceFactory
class);
url
(showing the required syntax for referencing the specifi c database on the
specifi c host).
Of course, the reader will need to determine the appropriate values for the host
(including port number) and database reference for the required database at his/her
own site and use these in the
url
attribute.
Example
<Context path="/myapps" docBase="myapps" debug="0"
reloadable="true">
<Resource
name="jdbc/Finances"
type="javax.sql.DataSource"
auth="Container"
username="cmsjg3" password="opensesame"
driverClassName="com.mysql.jdbc.Driver"
url=
"jdbc:mysql://ivy.shu.ac.uk:3306/"
+"cmsjg3_Finances"
/>
</Context>
*** Note that the JAR fi le holding the database driver must be in <JAVA_
HOME>\jre\lib\ext .
Search WWH ::
Custom Search