Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

jdbc ResultSet to XML

Posted on 2008-10-30
6
1,251 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
How our DevOps Teams Maximize Uptime

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

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 213
Should localization be done inside spring controller 5 32
check java version using powershell 13 177
Android development question 2 54
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

828 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