Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes What does resource-ref do for you? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What does resource-ref do for you?" Watch "What does resource-ref do for you?" New topic
Author

What does resource-ref do for you?

Mark Williams
Ranch Hand

Joined: Aug 01, 2008
Posts: 66
I hope this is the right forum...

When you set up a JDBC datasource on an application server, at least in my experience, you must give a JNDI name to that datasource. However, in the deployment descriptor for the application we also have the resource-ref entry that references the JNDI name of the datasource. What is the idea behind the resource-ref entry in the deployment descriptor?
Abhijit Rai
Ranch Hand

Joined: Aug 07, 2008
Posts: 41
Hi Mark,

When you set up a JDBC datasource on an application server, at least in my experience, you must give a JNDI name to that datasource.

Clarification:
You can access a database with the JDBC API without using JNDI ,but yes when it comes to datasource you have to use some naming service,I too have used JNDI.
As for the question ,
There are many reasons that according to the specification, one should also specify the <resource-ref> in web.xml. One of the most important reasons is the scope of the DataSource being used.

<resource-ref>
. . .
<res-sharing-scope>Shareable</res-sharing-scope>
. . .
</resource-ref>

You can read more about that in the following thread

http://www.coderanch.com/forums/posts/watch/0/159428

SCJP5 ,SCWCD5
Mark Williams
Ranch Hand

Joined: Aug 01, 2008
Posts: 66
Thanks for the reply... and yes, I do realize that JNDI is not the only way to access your JDBC driver/connection.

So, what I am starting to think is that the resource-ref entry really applies more EJBs are used. I am just using POJOs for my JDBC so I think I will just add it to my web.xml and not think about it too much (unless it breaks ).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What does resource-ref do for you?