0

I am trying to extract XML datatype from Oracle table and facing this exception:

java.lang.NullPointerException: null
at oracle.jdbc.driver.NamedTypeAccessor.getOracleObject(NamedTypeAccessor.java:302) ~[ojdbc6-11.2.0.3.0.jar:11.2.0.3.0]
at oracle.jdbc.driver.NamedTypeAccessor.getSQLXML(NamedTypeAccessor.java:413) ~[ojdbc6-11.2.0.3.0.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleResultSetImpl.getSQLXML(OracleResultSetImpl.java:1251) ~[ojdbc6-11.2.0.3.0.jar:11.2.0.3.0]
at oracle.jdbc.driver.OracleResultSet.getSQLXML(OracleResultSet.java:488) ~[ojdbc6-11.2.0.3.0.jar:11.2.0.3.0]

Code snippet:

SQLXML sqlxml = resultSet.getSQLXML(1);

I have double checked the query which is fetching resultset and it is working as expected. Also I am facing this issue only for XMLType column.

1 Answer 1

1
  public static void main(String[] args) throws SQLException, Exception {
        Connection con = ConnectionDefinition.getOracleConnection(); //my oracle connection
        PreparedStatement ps = con.prepareStatement("SELECT a.b FROM xml_test a");       
        ResultSet rs = ps.executeQuery();
        while(rs.next()){
           if( rs.getObject(1) != null ){
                 SQLXML xml = rs.getSQLXML(1);
                 System.err.println(xml.getString());
           } else {
                 System.err.println("xmltype is null");
           }                     
        }
        rs.close();
        con.close();        
    }

And pom dependency. I recommend to use oracle drivie in 11.2.0.4 version.

<dependencies>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.4</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>xdb</artifactId>
        <version>11.2.0.4</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>xmlparserv2</artifactId>
        <version>11.1.2</version>
    </dependency>
</dependencies>
Sign up to request clarification or add additional context in comments.

5 Comments

is there any official location to doanload xmlparserv2 jar?
Official is Oracle XDK. But I have Found this jar in JDeveloper libraries. Or this link can be helpful findJar
But you still get java.lang.NullPointerException: null?
Edit your question and include more java code and sql query
I was using xmlparserv2 downloaded from findjar. which was an old version. Then I used xmlparserv2 jar from JDeveloper 11.1 generic release downloaded from oracle.com/technetwork/developer-tools/jdev/downloads/… and it worked. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.