1

I have can not deal with execute my java method on oracle server. I load my java class on database using loadjava and create function using this query:

create or replace function getPeriodIdDay (multiplicity number, stardDate date, endDate date) return number
as language java
name 'Period.getPeriodIdDay(int, oracle.sql.Date, oracle.sql.Date) return int';

My method in class is:

  public static int getPeriodIdDay(int multiplicity, DATE startDate, DATE date){
       // day period calculation
       int dayPeriodId =  (date.dateValue().getTime() - startDate.dateValue().getTime()) / MILLIS_IN_DAY;
       return dayPeriodId / multiplicity;
   }

Each time when try to execute this function I have get this error:

29531. 00000 -  "no method %s in class %s"
*Cause:    An attempt was made to execute a non-existent method in a
           Java class.
*Action:   Adjust the call or create the specified method.

What am I doing wrong?

2 Answers 2

3

The signature of the java method in your function declaration is:

Period.getPeriodIdDay(int, oracle.sql.Date, oracle.sql.Date) return int

but the signatur of the metho in the java class itself is:

int getPeriodIdDay(int multiplicity, DATE startDate, DATE date)

If the capitalisation of DATE is no mistake when copying it here then this is a different type.

And even if it is a copy mistake: check with the imports of the java class that the same Date class is used.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, u have right i should use DATE insted of Date.
1

the problem seems to be the DATE class, I suggest you to use String instead

You better change your method class like this:

CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED JTESTDATE AS 
import java.text.SimpleDateFormat;
import java.util.Date;

public class TestDate {
    public static int getDate(int multiplicity, String startDate,
            String endDate) {
        SimpleDateFormat sf = new SimpleDateFormat();
        sf.applyPattern("yyyymmdd");//You Have to specify format here
        Date sd;
        try {
            sd = sf.parse(startDate);
        } catch (Exception e) {
            return -1;
        }
        Date ed;
        try {
            ed = sf.parse(endDate);
        } catch (Exception e) {
            return -2;
        }
        long dayPeriodId = (ed.getTime() - sd.getTime()) / 24 * 60 * 60;//this is replaced with your code
        return (int) (dayPeriodId / multiplicity);
    }
}

1 Comment

Sorry, that was mistake, function name in oracle and java are the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.