This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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 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 "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: 41591
    
  55
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: 61082
    
  66

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: sql query in web.xml or property file