?
Solved

jdbc ResultSet to XML

Posted on 2008-10-30
6
Medium Priority
?
1,268 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
[X]
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
  • 2
  • 2
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 1050 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 1050 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 450 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses
Course of the Month14 days, 15 hours left to enroll

771 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