Solved

jdbc ResultSet to XML

Posted on 2008-10-30
6
1,238 Views
Last Modified: 2008-11-18
HI all,
        I want to convert the ResultSet returned after running the query "SELECT * FROM TABLE" into a XML file. Please suggest me the simplest way to do it. If possible, some automatic means of it.
        If nothing works out then I wont mind hardcoding the XML document, before I put if all the values in it from the resultset, for this I need a sample code. please help me out with it from the basic level.
0
Comment
Question by:aman0711
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 350 total points
ID: 22844579
You could serialize an object to xml.  If you load the Recordset xml data into a Serializable Java object.

http://www.developer.com/xml/article.php/1377961
0
 
LVL 10

Author Comment

by:aman0711
ID: 22844634
I am sorry I didnt mention the complete Scenario. I dont want a dump of XML. I have to feed that XML file into Fusion Charts, so that I can display it one the JSP pages for the website.
0
 
LVL 15

Accepted Solution

by:
SRigney earned 350 total points
ID: 22844698
You can still use the Serializer, but instead of serializing to a file you can serialize to a stream which loads it into memory.  


Here is a way to serialize an Account object to a stream.   You would need to do the same thing using the xml serialization to a stream.  Then you can pass it wherever you want.


    protected Object clone() throws CloneNotSupportedException {

        try{

            ByteArrayOutputStream byteOut=new ByteArrayOutputStream();

            ObjectOutputStream objectOut=new ObjectOutputStream(byteOut);

            objectOut.writeObject(this);

            ByteArrayInputStream byteIn=new ByteArrayInputStream(byteOut.toByteArray());

            ObjectInputStream objectIn=new ObjectInputStream(byteIn);

            return objectIn.readObject();

        }catch(Throwable t){

            throw new RuntimeException("Error copying current object data: " + t.getMessage(),t);

        }

        

    }
 
 

myObject =(Account) this.clone();

Open in new window

0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 150 total points
ID: 22853339
Perhaps this is what you're looking for? It will turn a ResultSet into xml:

http://technojeeves.com/joomla/index.php/free/60-resultset-to-xml
0
 
LVL 10

Author Comment

by:aman0711
ID: 22879569
Hi guys,
    Thanks for helping me out. Here is a real simple way to do it.
 
    http://www.rgagnon.com/javadetails/java-0511.html
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 22986642
:-)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Checkbox and ListView in Android Layout 4 56
Java - Why doesn't this JFrame work 3 40
HSSFWorkbook cannot be resolved error 10 49
varialbe initialization 11 30
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now