This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Servlets and the fly likes Datasource in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Datasource in web.xml" Watch "Datasource in web.xml" New topic
Author

Datasource in web.xml

Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
hi,

What is the advantage of specifying datasource reference in web.xml ? Is it necessary that datasource reference should be added to web.xml?

Regards,
Ajay.
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
You can acyiure it declaratively by specifying in your web.xml something like




There's nothing stopping you from using data sources programmatically instead of declaratively. Having declarative approach is preferable because you code can concentrate more writing business logic as opposed to infrastructure services.


java j2ee job interview questions with answers | Learn the core concepts and the key areas
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56191
    
  13

Originally posted by ak pillai:
You can acyiure it declaratively by specifying in your web.xml something like


acyiure?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
ak pillai
author
Ranch Hand

Joined: Feb 11, 2006
Posts: 288
was meant to write acquire.
Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Thanks for your reply Arul.

If we don't specify it in web.xml
is there any other way we can acquire datasource connection in our web application?

Regards,
Ajay.
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
You can also do it from server.xml.

In Tomcat 5.5.8, you can put this tag within the innermost tag (<Host> tag)




Naseem
[ July 13, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3652

You could put it in a properties text file if you have a lot of other properties you need to store. It doesn't matter where you put it (web.xml, text file, or setup a database connection pool on the server*) as long as its not hardcoded into the java file.

*Best solution


My Blog: Down Home Country Coding with Scott Selikoff
Ajay Xavier
Ranch Hand

Joined: Jan 03, 2005
Posts: 109
Hi scott,
You could put it in a properties text file if you have a lot of other properties you need to store. It doesn't matter where you put it (web.xml, text file, or setup a database connection pool on the server*) as long as its not hardcoded into the java file.

Do you mean this?

We have to create a datasource in the Application server and bind it with a JNDI name. The Jndi name can be given either in the web.xml or a properties file.

Regards,
Ajay.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Datasource in web.xml
 
Similar Threads
A basic problem
NameNotFoundException
Looking up JNDI without reference
websphere and db2 connection pool problem
WAS7: Resource reference for Datasource