aspose file tools*
The moose likes XML and Related Technologies and the fly likes XML support in MySQL? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML support in MySQL?" Watch "XML support in MySQL?" New topic
Author

XML support in MySQL?

Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Seems that MySQL doesn't supports XML type column directly (correct & pardon me, if I'm mistaken), does anyone here has any simple workaround?

Thought about keeping it as a VARCHAR, but I'd have to convert the string back into a XML file, which means more work. Or is there some APIs around for this task (couldn' seem to find one yet at Apache)

Or could I store an entire POJO into a column of MySQL tables? If this is possible, I could retrieve the POJO & convert it into a XML file instead. Does MySQL supports Java object columns?


SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

XML is a text format anyway so a VARCHAR seems perfectly reasonable to me. I don't understand your problem with converting such a column to an XML file: simply read the column to a string and write that to the file using a PrintWriter.
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
I use a TEXT field in mysql to store the XML. The POJO is converted to XML (using XSTream) and stored as a String which is mapped to the dbase through a Hibernate hbm file.

For example the following:

xStream=new XStream();
mydBaseRecord.XMLdataField=xStream.toXML(myXMLPOJO());
session.save(mydBaseRecord);

Where XMLdataField is of type string and gets stored in a TEXT field.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Originally posted by Paul Clapham:
XML is a text format anyway so a VARCHAR seems perfectly reasonable to me. I don't understand your problem with converting such a column to an XML file: simply read the column to a string and write that to the file using a PrintWriter.


If I'm not mistaken, there's a size limit on VARCHAR, so if my XML file is large, I may have a problem with it.
Chengwei Lee
Ranch Hand

Joined: Apr 02, 2004
Posts: 884
Originally posted by Gerardo Tasistro:
I use a TEXT field in mysql to store the XML. The POJO is converted to XML (using XSTream) and stored as a String which is mapped to the dbase through a Hibernate hbm file.

For example the following:

xStream=new XStream();
mydBaseRecord.XMLdataField=xStream.toXML(myXMLPOJO());
session.save(mydBaseRecord);

Where XMLdataField is of type string and gets stored in a TEXT field.


Thanks, this is the missing API that I was looking for.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML support in MySQL?