Question:
Hello, Good morning at my company we are testing Oracle 12c. And I found a "little problem" to query a field which is XMLType type. We store all nfe xml in the bank so we always have to consult this xml. The problem is the following, when I do the query in Oracle 12, the xml is formatted, and so it loses the file's digital signature. Does anyone have any tips on how to bring this unformatted xml?!? any help is most welcome. Here is my code:
PreparedStatement st = con.prepareStatement("select nfe_xml from nfe_xml where NFE_CHAVE_ACESSO = ?");
st.setString(1, chaveAcesso);
ResultSet rs = st.executeQuery();
OracleResultSet orset = (OracleResultSet) rs;
while(orset.next())
{
//orset.getOPAQUE(1);
//XMLType poxml = XMLType.createXML(orset.getOPAQUE("NFE_XML"));
XMLType poxml = (XMLType)orset.getObject(1);
String sXml = ( poxml).getStringVal();
System.out.println("xml: "+sXml);
podoc = (Document)poxml.getDOM();
Util.gravarXmlNfe("C:\\NFE\\"+chaveAcesso+".xml", podoc);
String sXml2 =Util.convert(podoc, null) ;
System.out.println(sXml2);
}
Answer:
Instead of using the getStringVal
method to get the XML content, you can use the getInputStream
method which returns an InputStream
for you to read the XML byte byte from the database.
Make sure that the XML is being written to the database in a column of type LOB
, as this is the only way in which the original information will be preserved. This documentation is explained.