This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Insert XML document directly into database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Insert XML document directly into database" Watch "Insert XML document directly into database" New topic
Author

Insert XML document directly into database

Jeppe Sommer
Ranch Hand

Joined: Jan 07, 2004
Posts: 270
Hi,

I have created a XML document using JDOM and is printing the document out in the browser on the fly. See the code below.

Now I want to change the code, so it inserts the XML document into the database as a blob without storing the file on the server. How is that possible?

I need somehow to convert the Document to a binaryStream, but how can I do that?



[ November 02, 2006: Message edited by: Jeppe Fjord ]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Have your XMLOutputter write to a ByteArrayOutputStream (by the way, it's always a better policy to write XML to an OutputStream rather than a Writer, unless you take the trouble to make your Writer have the same encoding as the XML, which you didn't). Then get the byte array from that. Then create a ByteArrayInputStream from that byte array. You know what to do from here on.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Insert XML document directly into database
 
Similar Threads
How to transform an XML document to Java objects
\r\n\r\n gets appended to a message sent via socket
Validate on the fly
ftp question
Allowing & br tags to show using XSL