This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Servlets and the fly likes sql query in web.xml or property file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "sql query in web.xml or property file" Watch "sql query in web.xml or property file" New topic
Author

sql query in web.xml or property file

Ankur Bohra
Greenhorn

Joined: Jun 29, 2007
Posts: 19
Hello,

anyone who can help me with some code example of writing a sql query in web.xml or property file.
as i am developing a application with a variable sql query which may change any time.

Select query
Update query
Insert Query


Sun Certified Java Programmer<br />Sun Certified Web Component Developer <br />National Stock Exchange Certification in Financial Market
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
I would put it into a properties file. That way you can write code to reload the file contents at runtime when a particular URL is hit. That's not possible if you put it into web.xml (for which you'd need to reload the whole web application).


Ping & DNS - my free Android networking tools app
Ankur Bohra
Greenhorn

Joined: Jun 29, 2007
Posts: 19
But how can i write a insert query in property, where each time my parameters changes
Hussein Baghdadi
clojure forum advocate
Bartender

Joined: Nov 08, 2003
Posts: 3479

But how can i write a insert query in property, where each time my parameters changes


How a property file would differ from web.xml if you are hard coding your SQL into them?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If you use prepared statements you can list your parameters as '?' symbols.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61451
    
  67

Originally posted by John Todd:


How a property file would differ from web.xml if you are hard coding your SQL into them?

Because property files can be reloaded at any time.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Radhakrishna Bhat
Greenhorn

Joined: Dec 26, 2007
Posts: 10
Here is what i do in my applications.

use context-param to store connection strings.

use properties file for Queries.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql query in web.xml or property file