• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to put java.util.Properties into XML column of Sql Server

 
Kjeld Sigtermans
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • 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

 
Scott Selikoff
author
Saloon Keeper
Posts: 4031
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic