This section covers how to troubleshoot Java class libraries. Some of this becomes intuitive after a while but initially it is very tricky.
Building, Loading, and Dropping Java Class Library Objects
When you build Java class libraries, you can encounter a number of problems. Many errors occur through simple syntax rule violations, but often the PATH or CLASSPATH environment variable excludes required Java libraries. You need to ensure that your PATH environment variable includes the Java SDK released with the Oracle database youíre using. Itís best if you research which Java class libraries youíll require and then source them into your CLASSPATH. The following illustrates the minimum for the examples used in this chapter by the operating system:
C:> set PATH=%PATH%;C:%ORACLE_HOME%\jdk\bin C:> set CLASSPATH=%CLASSPATH%;C:%ORACLE_HOME%\jdbc\lib\classes12.zip
If you want to use the JPublisher command-line tool, you need to add both of the following Java archive files:
# export PATH=$PATH:/<mount>/$ORACLE_HOME/jdk/bin
If you want to use the JPublisher command-line tool, you must add both of these Java archive files to your CLASSPATH environment variable:
Another potential problem in configuring Java archive access can be found in the LD_LIBRARY_PATH used in the listener.ora file. Check to make sure itís set as follows:
You may also encounter an error like this, which says you cannot drop a Java class file directly from your database instance. The error is raised by running the dropjava utility with the following syntax:
C:> dropjava -u plsql/plsql HelloWorld4.class
The following error message should then appear:
Error while dropping class HelloWorld4
The reason for the error is that you used loadjava with the source file, HelloWorld4.java. Thus, you should use dropjava and the source file, which will delete the class and source file.
The error signaling that you have excluded something from your CLASSPATH environment variable should appear as follows:
C:\>loadjava -r -f -o -user plsql/plsql HelloWorld4.class
If you get an ORA-29549 error, youíre missing a Java archive reference. As noted early in the chapter, an ORA-29549 error is also raised when the Java class is removed and replaced the first time itís called.
Now that youíve reviewed the major issues with building, loading, and dropping Java stored object class files, letís examine some errors in the SQL and PL/SQL environment.
Using Java Class Library Objects
When you use Java stored object classes, you should ensure you define only one constructor in the PL/SQL object type definition. The only constructor acted on by a PL/SQL object type wrapper is the default constructor.
An example of overriding constructors being ignored is found in the HelloWorld4e.sql script. The script references the HelloWorld4.class file addressed earlier in the chapter. HelloWorld4e.sql defines two constructors for the HelloWorld4.class file. One is a null argument constructor and the other is a single formal parameter argument. Since thereís no duplicate constructor defined in the targeted class file, you would expect the following object type definition to fail:
-- Available online as part of HelloWorld4.sql file.
It does not fail, however, and instead succeeds to define a type that misrepresents the internal Java programís capabilities. You can run this test program found in the HelloWorld4e.sql script, which demonstrates that the type fails to support the overriding constructor:
-- This is found in HelloWorld4e.sql file.
This will send the following output to your console:
-- This output is generated from the HelloWorld4e.sql file.
This would imply that the overriding constructor takes a single VARCHAR2 formal parameter and cannot support a VARCHAR2 value. The real issue is that the SQLData type is what is passed and itís managed as a SQLData type. As noted earlier, the methods used in the SQLData interface define how values are passed.
You may encounter many issues when first implementing stored Java object classes and thus may benefit from building a java_debug error management table like the following:
CREATE TABLE java_debug
Adding the following method to your Java class files will enable you to write to the java_debug table:
// Define the debugLog() method.
You have now covered the major issues with troubleshooting Java stored object classes. The next section summarizes the mapping of Oracle types to Java types.
blog comments powered by Disqus