• 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 store whole XML in a table of a database

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an XML created dynamically and now i want to store the whole xml (including tags as well as data) but the problem is that i cannot store the whole xml as string in any database due to the maximum limit of char datatypes which is generally(255)
so i thought that i should store it as blob datatype but problem is that i donot know whether i have to serialize my xmldocument before stoeing it in table or will blob datatype will accept my xml object as it is.I m very confused
Ajit kalambela will u throw some light on my confusion as u are a moderator.any other fellow can u give some idea???
Thankx in advance
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your XML document is just a chunk of textual data. You don't mention what database you're using but from the sound of it a CLOB would be most appropriate. No need for serialization.
As an aside -- there are roughly three ways you can store an XML file in a database.

  • As a flat text field, without attempt to represent the structure of the XML file in the database. This is what you are planning to do.
  • As structured data in a set of tables, each table representing an XML construct (e.g. tag, attribute, cdata). This is how many generic XML database tools work. Although storage is structured, the database schema reflects the structure of XML itself rather than the structure of your file.
  • Completely decomposed into a set of tables, which between them represent your DTD (or rather XML Schema). The structure of your XML document is directly reflected in the database.

  • Of course, you can mix and match between these three. Which alternative you choose depends on what you want to do with the data -- the first is most appropriate if you just want to store the file, the last is most appropriate if you need to process or query the data on the same footing with all other database data.
    - Peter

    [This message has been edited by Peter den Haan (edited March 11, 2001).]
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter
I m not using any schema with my XML Document
so thats why i did not get (or understood) your third option
and as per your suggestion of implementing in first way
so as a flat text field how can i store the xml document object in a table
will it not say for datatype incompatibility as clob datatype and my xmldocument object donot have an datatype
can u Please elaborate it little further I will be thankful to you
regarding your database question it is either SQL Server7.0
or Oracle 8.0 (not finalised yet)
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Open an input stream to the XML file and using PreparedStatement, pstmt.setAsciiStream(1, <stream from file> );, this will insert the file into the database.
David
 
Gaurav Chikara
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This function of PreparedStatement has a third paramater
called length but how can we know the length of InputStream of a file which is dynamically created??
and there is one more function in PreparedStatement called
setBlob(int x,Blob y)
will it help
if yes then do we have to give the xmlobject name as a Blob argument in this function???

[This message has been edited by Gaurav Chikara (edited March 12, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic