Home » Developer & Programmer » JDeveloper, Java & XML » PLS-00311 Error when creating java stored function
PLS-00311 Error when creating java stored function [message #251754] Mon, 16 July 2007 09:54 Go to next message
sr_best73
Messages: 3
Registered: July 2007
Junior Member
I've successfully loaded my java class using loadjava into an Oracle 9.2.1 database. The issue I have is in creating the PL/SQL wrapper to call the valid java classes in an Oracle Function. The class in question is stored in the db as: barcoderapp/BarCodeEncoder . The name of the function I'm creating the wrapper for is getEncodedString and it accepts a java string as a parameter and returns a string as the result.

I've tried using the following code segments individually to create the wrapper:

CREATE OR REPLACE FUNCTION ENCODEFORPDF(theDecodeString VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'getEncodedString(java.lang.String) RETURN java.lang.String';

CREATE OR REPLACE FUNCTION ENCODEFORPDF(theDecodeString VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'BarCoderEncoder.getEncodedString(java.lang.String) RETURN java.lang.String';

CREATE OR REPLACE FUNCTION ENCODEFORPDF(theDecodeString VARCHAR2) RETURN VARCHAR2
AS LANGUAGE JAVA
NAME 'barcoderapp.BarCoderEncoder.getEncodedString(java.lang.String) RETURN java.lang.String';


The reason there are three different segments is because I'm not sure how Oracle references packages.

Each time I try any of the above code segments I get a PLS-00311 error indicating my declaration of the java object is incomplete or malformed. Does anyone have any idea what is going on? My java source accepts/returns a single String and works perfectly outside of the Oracle environment.

My simple class imports the IDautomation encoder package. Here is my java code:

package barcoderapp;

import IDautomationPDFE.PDF417Encoder;

public class BarCodeEncoder {
    
    public BarCodeEncoder() {
        
    }
    
    public String getEncodedString(String theData){
        String dataToEncode = theData;
	PDF417Encoder theEncoder= new PDF417Encoder();
	theEncoder.PDFECLevel = 3;
        theEncoder.PDFColumns = 7;

	return theEncoder.fontEncode(dataToEncode);
        
    }


IDautomation's fontEncode function accepts/returns a simple string.

[Updated on: Mon, 16 July 2007 10:14]

Report message to a moderator

Re: PLS-00311 Error when creating java stored function [message #252024 is a reply to message #251754] Tue, 17 July 2007 12:41 Go to previous messageGo to next message
sr_best73
Messages: 3
Registered: July 2007
Junior Member
I've managed to resolve this one ... here is my solution:

The correct syntax is as follows:
CREATE OR REPLACE FUNCTION ENCODEFORPDF(theDecodeString VARCHAR2) RETURN VARCHAR2
IS LANGUAGE JAVA
NAME 'barcoderapp.BarCoderEncoder.getEncodedString(java.lang.String) RETURN java.lang.String';

After successful compilation I ran into another issue. I ran the following SQL Statement:
SELECT ENCODEFORPDF('This is a test') FROM DUAL;
and received an ORA-29531 error: method does not exist.

After some investigation I learned that in order for Java Functions to be called in Oracle they need to be declared as STATIC. So, to do this I followed the procedure below:

1)From the Oracle Bin directory I ran the dropjava util to drop the applicable generated class.

[Dir:]\Oracle\Bin> dropjava BarCodeEncoder.class

If the generated class is not dropped prior to running the code below, an error may result.

2) Logged into SQL Plus, reloaded and compiled the java source (making sure to include the static keyword) using the following lines:
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "BarCodeEncoder" AS 
package barcoderapp;
import IDautomationPDFE.PDF417Encoder;
public class BarCodeEncoder {
public BarCodeEncoder() {
}
public static String getEncodedString(String theData){
String dataToEncode = theData;
PDF417Encoder theEncoder = new PDF417Encoder();
theEncoder.PDFECLevel = 3;
theEncoder.PDFColumns = 7;
return theEncoder.fontEncode(dataToEncode);
}
}
/

Be sure to omit tabs and place your code on every line to ensure SQL Plus can interpret it properly. FYI: I loaded the IDautomation package prior to running the above code.

This compiled successfully. I then re-ran my test SQL
SELECT ENCODEFORPDF('This is a test') FROM DUAL;
and the encoded string was returned.

I hope this helps some others with similar problems ...

[Updated on: Wed, 18 July 2007 09:43]

Report message to a moderator

Re: PLS-00311 Error when creating java stored function [message #252044 is a reply to message #252024] Tue, 17 July 2007 13:14 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Great! I'm glad you managed to solve the problem and thankful for sharing the solution with the rest of the community.

However, saying
Quote:
For Oracle 9.2.1 the Function declaration uses IS rather than AS

sounds *very* strange because - ever since I know for Oracle functions and procedures, IS was equal to AS - no difference at all.

So, if it is not a problem, could you post a link to that document, please?
Re: PLS-00311 Error when creating java stored function [message #252300 is a reply to message #252044] Wed, 18 July 2007 09:36 Go to previous message
sr_best73
Messages: 3
Registered: July 2007
Junior Member
Thanks for pointing out my error. You are correct. I will remove that section from my post.

Cheers,
Shannon
Previous Topic: Error in JAVA Stored Procedures while loading to Oracle
Next Topic: springframework.jdbc.UncategorizedSQLException
Goto Forum:
  


Current Time: Tue Apr 16 14:55:28 CDT 2024