Oracle 12C + Java + Xmltype

Asked

Viewed 219 times

3

Hello, Good morning in my company we are testing the Oracle 12c. And I found a "little problem" to query a field that is the type Xmltype. We store all the nfe xml in the database, so we always have to query this xml. The problem is this, when I do the query in Oracle 12, the xml comes formatted, and so loses the digital signature of the file. Does anyone have any hint on how to bring this unformatted xml?!? any help is very welcome. Follows 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);
}
  • 2

    Are you wearing any Feature specific XML manipulation in the database? If not a possible path is to replace its type with a CLOB.

1 answer

1

Instead of using the method getStringVal to obtain XML content, you can use the method that getInputStream that returns a InputStream for you to read the XML byte to byte of the database.

Make sure that XML is being written to the database in a column of type LOB, because only then will the original information be preserved. This is explained documentation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.