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 XML and Related Technologies and the fly likes Writting query in xml 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 » Engineering » XML and Related Technologies
Bookmark "Writting query in xml" Watch "Writting query in xml" New topic
Author

Writting query in xml

Varadhan Sesharaman
Ranch Hand

Joined: Apr 21, 2011
Posts: 30

Hi guys,

I want to know what is the main advantages of writing the sql query in xml format and then parsing to the sql format.

I need its main advantage and the comparison of it with the normal method of writing it in java file.


Thanks
Varadhan.s
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38472
    
  23
Moving to our XML forum.
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Keeping SQL out of code helps code maintainability. You can change SQL statements for only optimization needs in future still not re-building the code again.

Read - Keep SQL out of code
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10067
    
163

Varadhan Sesharaman wrote:

I want to know what is the main advantages of writing the sql query in xml format and then parsing to the sql format.


Do you have a reference where that's mentioned?

[My Blog] [JavaRanch Journal]
William P O'Sullivan
Ranch Hand

Joined: Mar 28, 2012
Posts: 859

So you can avoid this c**p:


That is a segment from a 114 line SQL statement, JOINing across 9 tables!

Whenever a developer has to change this, he or she must test (externally), the recompile the Class, rebuild the war, and redeploy.

Besides the minimal performance hit, storing SQL in XML will give you (if you do it right), tools like myBatis can really help.


WP
Palak Mathur
Ranch Hand

Joined: Jan 29, 2007
Posts: 313

Varadhan Sesharaman wrote:Hi guys,

I want to know what is the main advantages of writing the sql query in xml format and then parsing to the sql format.

I need its main advantage and the comparison of it with the normal method of writing it in java file.


Thanks
Varadhan.s


What do you mean by writing sql query in xml format? Do you mean to use XML to transfer data to and from database? Or do you mean that putting sql query as part of XML?


Palak Mathur | My Blog | TechJaunt | What is JavaRanch? | List of All FAQs
Varadhan Sesharaman
Ranch Hand

Joined: Apr 21, 2011
Posts: 30

Palak Mathur,

In some cases i saw the query files are kept out of the java code .

The query are written in xml using the proper xml tags and the in run time the queries are converted into a normal query and then executed in java.

I am asking is there any specific reason for keeping the query out of the java file.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
I am asking is there any specific reason for keeping the query out of the java file.


1. Ease of changing the query without having to recompile
2. Facilitates record keeping, you can document the query using XSLT to create a nicely formatted record.
3. Reduced chance of introducing errors into Java file
4. Facilitate use by non-java-programmers
5. Probably, better security but I'm not sure about that

Bill
Varadhan Sesharaman
Ranch Hand

Joined: Apr 21, 2011
Posts: 30

Thank you guys for those answers.

Now i had some idea on this concept.


Thanks,
Varadhan.s
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writting query in xml