wood burning stoves 2.0*
The moose likes JDBC and the fly likes jdbc resultset to xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "jdbc resultset to xml" Watch "jdbc resultset to xml" New topic
Author

jdbc resultset to xml

shru win
Greenhorn

Joined: Jul 30, 2010
Posts: 5
Hi,
I have to insert data into a database table using jsp and jdbc, query the table data and convert resultset into an xml file. I am using NetBeans IDE. I'm really stuck and i have a project due. Please do help.
Thanks in advance.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What have you written so far? What are you stuck on?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
shru win
Greenhorn

Joined: Jul 30, 2010
Posts: 5
I have to convert resultset into xml file. Inserting into database table and querying the contents of the table is done. But unable to generate xml file. . Please help.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

XML is just well formatted text data. Are you familiar with the java.io package and writing to files? And are you comfortable going through a ResultSet and accessing its contents?
amit punekar
Ranch Hand

Joined: May 14, 2004
Posts: 511
Hello,
I think Oracle gives you ability to fetch the data as XML itself. Might be helpful if you are fetching the resultset from Oracle.

Regards,
Amit
shru win
Greenhorn

Joined: Jul 30, 2010
Posts: 5
Thanks for your reply.
I am using postgresql. I'm pretty comfortable with resultset. I'm using netbeans IDE. This can be easily done using PHP.But in netbeans i'm unable to use php in java projects. So stuck.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

OK. So the steps will be:
  • move through your ResultSet and build up your formatted XML as a String
  • write it out to a file


  • Have you written the first bit? Or is that where you are stuck?
    shru win
    Greenhorn

    Joined: Jul 30, 2010
    Posts: 5
    Actually that is where am stuck.
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    OK, well the JDBC tutorial will show you how to access things from your ResutlSet, and the basic io second of the Java tutorial will show you how to do the other other part.
    shru win
    Greenhorn

    Joined: Jul 30, 2010
    Posts: 5
    I'v attached my code along with this. It's not working. This is the just a sample code i craetes to learn how it works. Inserting into database is perfectly working.
    Converting to xml is not. Please do tel me what m doing wrong.
    Paul Sturrock
    Bartender

    Joined: Apr 14, 2004
    Posts: 10336

    A couple of points: saying "its not working" makes it difficult to help. You need to tell us what is going wrong, especially if there is a stack trace. The other is code in a JSP is bad. I know this is just to learn, but it actually makes things harder to develop.

    That aside, I don't see any code that saves or streams your Document?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: jdbc resultset to xml
     
    Similar Threads
    Create a table using ResultSet ???
    ResultSet containing XML from SQL server 2000
    JDBC connection
    JDBC connection query
    CachedRowSet