2 Replies Latest reply: Aug 22, 2012 3:25 PM by rp0428 RSS

    (tmpResultSet).getSQLXML(2) throw java.lang.NullPointerException

    927224

      Hello,

      when trying to get the XML object from a resultset returned by a stored procedure, the (tmpResultSet).getSQLXML(x) throw a java.lang.NullPointerException object.

      The code should work ...

      PL/SQL code :
      procedure P_FIND_xxx_XML(
      pa_1 t_table.v_field1%type,
      pa_2 t_table.v_field2_version%type,
      pa_3 t_table.v_field3%type,
      pa_4 t_table.v_field4%type,
      pa_5 t_table.n_field5%type,
      pa_6 t_table.n_field6%type,
      pa_7 OUT SYS_REFCURSOR
      );

      JAVA:

      Connection tmpConnection = null;
      CallableStatement tmpStatement = null;
      ResultSet tmpResultSet = null;
      SQLXML tmpSqlXml = null;

      tmpConnection = getConnection();
      tmpStatement = tmpConnection.prepareCall("{call pa_xxx.p_find_xxx_xml(?,?,?,?,?,?,?)}");
      tmpStatement.setString(1, p1);
      tmpStatement.setString(2, p2);
      tmpStatement.setString(3, p3);
      tmpStatement.setString(4, p4);
      tmpStatement.setLong(5, p5);
      tmpStatement.setLong(6, p6);
      tmpStatement.registerOutParameter(7, OracleTypes.CURSOR);

      tmpStatement.execute();

      tmpResultSet = ((OracleCallableStatement)tmpStatement).getCursor(7);

      while(tmpResultSet.next())
      {

      tmpPKId = (tmpResultSet).getLong(1);
      if(tmpPKId != null)
      getLogger().info("performHistory --> " + "tmpPKId <");
      tmpSqlXml = (tmpResultSet).getSQLXML(2);
      if(tmpSqlXml != null)
      getLogger().info("performHistory --> " + "tmpSqlXml <NOT NULL OBJECT>");
      else
      getLogger().info("performHistory --> " + "tmpSqlXml <NULL OBJECT>");

      ...
      the code tmpPKId = (tmpResultSet).getLong(1); is OK and i have the value
      The (tmpResultSet).getSQLXML(2) throw an exception :
      java.lang.NullPointerException
      at oracle.jdbc.driver.NamedTypeAccessor.getOracleObject(NamedTypeAccessor.java:302)
      at oracle.jdbc.driver.NamedTypeAccessor.getSQLXML(NamedTypeAccessor.java:413)
      at oracle.jdbc.driver.OracleResultSetImpl.getSQLXML(OracleResultSetImpl.java:1251)

      Any idea ?

        • 1. Re: (tmpResultSet).getSQLXML(2) throw java.lang.NullPointerException
          725913
          Killed myself for a day on this exact issue - add xmlparserv2.jar to your classpath (ORACLE_HOME /xdk/lib folder)

          I was blowing up with same error on oraRs.getOPAQUE();

               public Object handle(ResultSet rs) throws SQLException {
                    ArrayList<Object> docList = new ArrayList<Object>();
                    OracleResultSet oraRs = (OracleResultSet) rs;
                    XMLTypeFactory fact = new XMLTypeFactory();
                    
                    while( rs.next() ) {
                         
                         OPAQUE val = oraRs.getOPAQUE("THE_XML");
                         XMLType x = (XMLType) fact.create(val, XMLTypeFactory._SQL_TYPECODE);
                         docList.add( x.getDocument() );

                    }
                    return docList;
               }
          • 2. Re: (tmpResultSet).getSQLXML(2) throw java.lang.NullPointerException
            rp0428
            >
            I was blowing up with same error on oraRs.getOPAQUE();
            >
            So? A lot of code blows up with null pointer exceptions. That doesn't mean the problem is at all related.

            OPs problem is that this variable is declared
            ResultSet tmpResultSet = null;
            And OP says this line of code is the problem
            The (tmpResultSet).getSQLXML(2) throw an exception :
            OP is trying to cast the variable name instead of the class using '(tmpResultSet)'.

            But OP has several other errors in the code like
            tmpResultSet = ((OracleCallableStatement)tmpStatement).getCursor(7);
            You can't cast a result set as a callablestatement.

            Whatever problems you are having are unrelated to OPs problems which were 4 months ago.