0

We have to pass XMLTYPE as a input parameters in Oracle stored procedure from java.

We convert XML file into XMLTYPE by using XMLType(connection, inXml). After execution of line#5, the control goes to line#12 and line#6 to line#8 are skipped. There is no exception raised. We don't know exactly what XMLType(connection, inXml) doing internally.

After line#5, it skip remaining line and control goes to line#12 and even no exception raised.

We manually check null at line#12 and throw exception.

Can anyone help us to identify what is the problem with this code?

We using below java and db version,

Java : 7

DB : Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Jar for XMLTYPE : xdb6.jar and xmlparserv2-12.1.0.2.jar

JDBC connection type : thin

Below is the sample code,

1 XMLType xmlFileInXmlType = null;
2 File xmlFile = new File("D:\\filePath\\ALP.xml");
3 FileInputStream inXml = new FileInputStream(xmlFile);
4 try {
    5 xmlFileInXmlType = new XMLType(connection, inXml);   
    6 CallableStatement cs = connection.prepareCall(call XXXX.XXXX(?));
    7 cs.setObject(1, xmlFileInXmlType);
    8 cs.execute();
9 }catch(Exception e) {
    10 throw e;
11 }finally {
    12 if(xmlFileInXmlType == null) {
        13 throw new Exception("XML File cannot able to convert into XML Object");
    14 }
15 }
Parthiban
  • 105
  • 4
  • 16
  • If lines 6-8 are skipped then an exception is being thrown, and you're catching and re-throwing it; I would think you would see both somewhere, but maybe the second exception you throw in the finally block is masking the original somehow? What happens if you remove that second throw? – Alex Poole Jun 18 '19 at 14:08
  • No, Exception is not thrown. I have debug the code. Line#6 to line#8 are skipped and control goes to line#12, after executing line#5 – Parthiban Jun 18 '19 at 14:27
  • An exception must be thrown at line 5. There is no other reason it would not reach line 6. You cannot see it because you throw your own exception. (I assume your exception stack refers to line 13 and line 10, but only with your fixed message.) Again, remove the second throw (or the whole finally block) for now and see what happens. If you have done some debugging then include what that showed in your question - actual code and output rather than vague assertions. – Alex Poole Jun 18 '19 at 14:39
  • I have tried many times. Exception is not thrown at line#5. I have checked in internet and didn't get clear information about how XMLType(connection, inXml) is working internally. Do you have any link about XMLType(connection, inXml)? – Parthiban Jun 18 '19 at 14:58
  • You mean [the documentation](https://docs.oracle.com/database/121/JAXML/oracle/xdb/XMLType.html)? – Alex Poole Jun 18 '19 at 15:01
  • Yes, documentation or web link – Parthiban Jun 18 '19 at 15:02
  • Well, I linked to the documentation in my previous comment. How it works internally shouldn't matter, it's supposed to be opaque. But as we don't know what you have tried or what debugging you've done, or even whether you've done what I suggested in earlier comments, I don't see how we can help you. With the right set-up I can run your code without any issues; without a [mre] including how you're building and running this, I don't know what I'm doing differently. – Alex Poole Jun 18 '19 at 15:21
  • Also [please see this question](https://stackoverflow.com/q/3779285/266304) for explanations of why your throw inside your finally block is being seen and why it appears that there is no exception thrown at line 5 (though there really is one). Just take out that second throw and you'll see the exception that is really being thrown. – Alex Poole Jun 18 '19 at 15:27

0 Answers0