Solved

jdbc ResultSet to XML

Posted on 2008-10-30
6
1,234 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

758 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

21 Experts available now in Live!

Get 1:1 Help Now