Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jdbc resultset to xml

 
shru win
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you written so far? What are you stuck on?
 
shru win
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 544
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Actually that is where am stuck.
     
    Paul Sturrock
    Bartender
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 10336
    Eclipse IDE Hibernate Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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?
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic