I have a query that creates XMLElement which gives "SYS.XMLType" as output. I tried to fetch the data using XMLType it exits when I try to cast as given on the oracle website.
dppSummaryps = (OraclePreparedStatement) connDb.prepareStatement(dppSummary);
System.out.println("Prepared Statement before bind variables set:\n\t" + dppSummaryps.toString());
dppSummaryps.setString(1, readTimeStart);
dppSummaryps.setString(2, readTimeEnd);
// System.out.println("uwjdpps.dppSummary() " + dppSummaryps.toString());
ResultSet rs = dppSummaryps.executeQuery();
OracleResultSet ors = (OracleResultSet) rs;
ResultSetMetaData mdata = rs.getMetaData();
if (mdata.getColumnType(1) == OracleTypes.OPAQUE
&& mdata.getColumnTypeName(1).compareTo("SYS.XMLTYPE") == 0) {
// we know it is an XMLtype
System.out.println("YEAH XMLTYPE: Column name = " + mdata.getColumnTypeName(1));
}
while (ors.next()) {
// get the XMLType
OPAQUE poxml = ors.getOPAQUE("XML");
XMLType xmltype = (XMLType) poxml;
// get the XML as a string...
System.out.println(xmltype);
// xml = (XMLType) rs.getObject(1);
// dppSummaryType = rs.getString("XML");
String result = IOUtils.toString(poxml.getStream());
System.out.println(result);
try {
File targetFile = new File(FILE_PATH_XML + "test.xml");
// OutputStream outStream = new OutputStream(targetFile);
// outStream.write(result);
// IOUtils.closeQuietly(outStream);
} catch (Exception e) {
String err = e.toString();
System.out.println(err);
}