ClassCastException With 22.214.171.124 Oracle JDBC Driver When Getting XMLTYPE Column Value
(Doc ID 1305209.1)
Last updated on AUGUST 03, 2016
Applies to:JDBC - Version 126.96.36.199.0 to 188.8.131.52.0 [Release 11.2]
Information in this document applies to any platform.
***Checked for relevance on 21-Jan-2014***
When getting XMLTYPE column value as an oracle.xdb.XMLType object,
with the version 184.108.40.206 of Oracle JDBC driver, the following exception is thrown:
java.lang.ClassCastException: oracle.jdbc.driver.OracleSQLXML cannot be cast to oracle.xdb.XMLType
To illustrate this problem, the warehouse_spec XMLTYPE column is defined and filled as the following:
INSERT INTO warehouses VALUES (
In order to fetch the XMLTYPE column value, the following code is executed:
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select warehouse_spec from warehouses");
Object o_xml = rs.getObject(1);
XMLType xmltype = (XMLType)o_xml; // here : with 220.127.116.11 driver ClassCastException
System.out.println(" xmltype value = " + xmltype.getStringVal());
The problem (ClassCastException is thrown) is happening with 18.104.22.168 Oracle JDBC driver:
Executing this code against the 22.214.171.124 JDBC driver, the XMTYPE column value can be obtained:
DriverName: [Oracle JDBC driver]
Oracle Database 11g Enterprise Edition Release 126.96.36.199.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
The JDK version is 1.6.0_22
xmltype value = <Warehouse whNo="100">
You can download the sample code (TestMLType.java) from here.
To execute this TestMLType program, just ensure:
- JDK 6 version is used
- and, the CLASSPATH contains the 188.8.131.52 ojdbc6.jar (Oracle JDBC driver, OH/jdbc/lib directory ), xdb.jar (XDB product, OH/RDBMS/jlib directory) and xmlparserv2.jar (XDK product, OH/lib directory) libraries. (OH stands for the Oracle Home 184.108.40.206 database server directory)
To view full details, sign in with your My Oracle Support account.
Don't have a My Oracle Support account? Click to get started!
In this Document