• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to read and write the data in XML file

 
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear ALL,

Below given the code i am retrive from Database.

Could you please tell me how this data should be read and write in XML file.



Please suggest.

Thanks in advance.
Regards,
Sumanta
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several APIs in Java for working with XML.

Unfortunately, the standard Java APIs for working with XML, in the package javax.xml and subpackages, are not the easiest and best to use in many cases. The standard APIs seem to be more focused on parsing XML and are not very good at outputting XML.

There are many alternatives, such as XOM (which XML guru Michael Kay said good things about on the Devoxx conference where I was recently), JDOM, XStream and many others.
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using the Oracle Database you can use the following pacakage.

select dbms_xmlgen.getxml('select sysdate from dual',0)xml from dual;

In the place of the 'select sysdate from dual' you can specify your query.

The data will automatically be generated in XML. You can also use the DOM Parser in java if this doesn't suit your requirement.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

Below given is the code.I am retrive the data from database and trying to export in the XML file.
I didnot get any compilation error.But i dont know why in my code the data is not export in the xml file.
hERE I TRIED WITH FNAME for column.

Please suggest me how i will fix this issue.



Thanks in advance.

Regards,
Sumanta Panda
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't ever close the output stream. You should do that.

Also, do you only have one record to output? If not, then you are reusing the same file for all records and you are going to end up with one file containing only the last record.
 
sumanta panda
Ranch Hand
Posts: 224
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Paul Clapham,

As per your advise i have closed the conncetion.Still i am getting the same issue(Data is not export in the file.

Please suggest me for the needful.



Thanks for your time.

Regards,
Sumanta
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

fos = new FileOutputStream(fileName);


Do you really want to create a new file for each DB record? Do you have code somewhere to assign them different filenames?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's another guess: your ResultSet doesn't contain any records. But this is a simple thing which you could find out for yourself by a little bit of debugging. Have you done any of that? Do you know which lines of code are being executed?
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you retrieve data from database using Hibernate ORM Framework, then all you need to do to get XML-based version is call toXML() on a single object.

Very easy! Hibernate is Great!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic