• 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 put java.util.Properties into XML column of Sql Server

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

I am trying to put an instance of java.util.Properties into a XML column of Sql Server using a JDBC PreparedStatement.

I defined a table containing a XML column based on a schema called properties.xsd. The latter is generated from http://java.sun.com/dtd/properties.dtd

When I try to execute my code I am getting this exception:
com.microsoft.sqlserver.jdbc.SQLServerException: Parsing XML with internal subset DTDs not allowed. Use CONVERT with style option 2 to enable limited internal subset DTD support.
Here's my code:
When properties.storeToXML is executed, it sends this XML content to the given outputstream:
As I described before I generated properties.xsd based on http://java.sun.com/dtd/properties.dtd and then I defined the table as follows:
properties.xsd Looks like this:

Does anybody know how to solve this, or should I perhaps try to remove the DTD line from the XML content?

Thanks,
Kjeld

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried adding the CONVERT() function to your SQL query as the error indicates?
 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did now.

I changed the prepared statement to:
INSERT INTO XMLPROPERTIESTEST(DATA) VALUES (CONVERT(XML, ?, 2))

But now it says:
com.microsoft.sqlserver.jdbc.SQLServerException: XML Validation: Required attribute 'version' is missing. Location: /*:properties[1]

For performance reasons I do not want to add a version attribute at runtime, or modify the XML stream in any way.
Obviously I could change the XSD (remove the required version attribute) but then I feel I deviate from the original DTD which can't be right?


 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To conclude this:
in the end I removed the part use="required" from the version attribute definition and it works now. Using the code I posted hereabove, I can store a properties object in the XML column and then query it with instructions like:



Thanks,
Kjeld
 
The knights of nee want a shrubbery. And a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic