Solved

jdbc ResultSet to XML

Posted on 2008-10-30
6
1,256 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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, …
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

730 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