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: WINDOWS 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: %ORACLE_HOME%\sqlj\lib\translator.zip
UNIX # 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: $ORACLE_HOME/sqlj/lib/translator.zip $ORACLE_HOME/sqlj/lib/runtime12.zip 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: LD_LIBRARY_PATH=C:\oracle\ora92\lib;C:\oracle\ora92\jdbc\lib 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 |
|
|
|
|
|
|
|