File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Greenhorn

Joined: Apr 21, 2011
Posts: 29

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: 36514
    
  16
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: 9329
    
110

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: 860

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
Greenhorn

Joined: Apr 21, 2011
Posts: 29

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: 12682
    
    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

Java Resources at www.wbrogden.com
Varadhan Sesharaman
Greenhorn

Joined: Apr 21, 2011
Posts: 29

Thank you guys for those answers.

Now i had some idea on this concept.


Thanks,
Varadhan.s
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writting query in xml
 
Similar Threads
Help needed
how to fetch data from resultset containing result of two queries
SQL to XML conversion
retrive data
Representing a SQL query in XML with a given DTD