ORA-29552   Java   Error     
          UnsupportedClassVersionError – Calling Java from PL/SQL  






You’re trying to extend PL/SQL functionality by calling a Java program from a PL/SQL wrapper function, and you get an error message along the lines of:


*  ORA-29552: verification warning: java.lang.UnsupportedClassVersionError: <class name> (Unsupported major.minor version 50.0)


when trying to load the compiled Java class using the operating system command “loadjava”.



What the Error Means


First, if you don’t regularly use Java, then the “major.minor” version notation – “50.0” in the present case – may be unfamiliar. You might be tempted to guess that “50.0” refers to Java 1.5, but, in fact, it refers to Java 1.6, as the following table illustrates:


Java VersionMajor Version


So, in the present case, the error message is saying that a class compiled (using “javac”) with JDK 1.6 is unsupported by the JRE that is being used to run the Java program (the JRE corresponds to a lower Java version, for example JRE 1.5).


Now the JRE is normally held somewhere in the file system, so it’s usually a question of examining the path variable to determine which JRE is being used (there may be more than one available). The solution is then either (1) to recompile the Java class using a lower version of JDK, one that is compatible with the JRE, or (2) to use a different JRE, one that is compatible with the JDK that has been used to compile the class.



Oracle Database Java Versions


In the case of running Java from PL/SQL, the JRE in question is built into the database, so the question becomes which JRE versions are associated with which Oracle database versions:


DB VersionJava Version


So, in the present case, the Java class was compiled with JDK 1.6, but the database only supports, at best, compilation with JDK 1.5. As many Oracle tools and other software require a JDK of 1.6, or greater, it’s quite common for this incompatibility between versions to occur.





Change JDK Version


While it’s not possible to upgrade the version of Java used by Oracle – to Java 1.6 in the present case – it is possible to install a compatible file system JDK, say Java 1.5, and recompile the Java class. The compiled class can then be loaded using the “loadjava” command.


Load Java Source


However, a faster workaround for this issue is to rely on the fact that the Oracle database contains not only a JRE, but also a JDK (of a matching version). Instead of loading the compiled Java class (by using “loadjava” with a file name of “<class name>.class”), it’s possible to load the uncompiled Java source code (by using “loadjava” with a file name of “<class name>.java”). In these circumstances, the source code will be compiled within the Oracle database using the inbuilt JDK and the class produced and stored internally will therefore be compatible with the JRE used to run it when called from the PL/SQL wrapper.


You can still externally compile and test the class using the later version of the JDK (provided you do not use any features not supported by the earlier JDK used by Oracle). And when you’re satisfied that it works, you can then load the source, rather than the compiled code, into the database.