How does a look-up like :
Context envContext = (Context)initContext.lookup("java:comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/MyDatasource");
proceed ?
I mean to say how is the name MyDataSource
searched and in the end what is returned ?
There are two entries added to connect to the database. One in the WEB-INF/web.xml
which is :
<resource-ref>
<description>my connection</description>
<res-ref-name>jdbc/MyDatasource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
and the other added in the META-INF/context.xml
which is :
<Resource name="jdbc/MyDatasource" auth="Container" type="javax.sql.DataSource"
driverClassName="org.apache.derby.jdbc.ClientDriver"
url="jdbc:derby://localhost:1527/My Database;create=true"
username="me" password="me"
maxActive="20" maxIdle="10" maxWait="-1" />
How does these 2 entries help in the look up ?
What is looked first : web.xml
or context.xml
?
Please explain the whole process in the look up.
resource-ref
tag from the web.xml I get an exception which saysName not found Exception
– Derris