简体   繁体   中英

Java method not found running on oracle database

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?

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.

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);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM