javaoracle19cojdbc

How to replace oracle.sql.STRUCT with java.sql.Struct, which is used by oracle.jpub.runtime.MutableStruct


Long story short, I have a project, which uses JPublisher to generate code from a PL/SQL package. At the moment, the project is running with ojdbc14.jar + the respective companion jars. However, I have to upgrade the driver to ojdbc8.jar + its' companion jars. At some point, in one of the classes I have the following code snippet:

oracle.sql.Datum d = <some value here>;
MutableStruct struct = new MutableStruct((STRUCT)d, sqlType, factory);

The constructor of the MutableStruct takes such arguments: (STRUCT arg0, int[] arg1, ORADataFactory[] arg2)

I checked this article and as you can see, it proposes to use java.sql.Struct instead. However, in this case the MutableStruct doesn't take such an argument and doesn't work.

So, my question is, whether there is any workaround of avoiding the deprecated STRUCT object in such cases?


Solution

  • You're not supposed to use MutableStruct directly either (probably, if it's a driver class). The correct way is to use the implementing classes through the Java interfaces, like java.sql.Struct. You can see that oracle.sql.STRUCT implements java.sql.Struct, so you'll be using that anyway, just through the JDBC interface.

    Nothing prevents you from just using the actual classes, but you might use some semi-internal operations that are removed or changed in another version, whereas the JDBC standard interface stays the same.

    Like your linked javadoc says, you can create a JDBC struct with java.sql.Struct struct = connection.createStruct(...);, but if you need to use MutableStruct then you might have to stick to the driver specific classes.