我无法在oracle服务器上执行我的java方法。我使用loadjava将java类加载到数据库中,并使用以下查询创建函数:
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';我上课的方法是:
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;
}每次尝试执行此函数时,我都会得到以下错误:
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.我做错了什么?
发布于 2017-01-11 11:31:33
函数声明中的java方法的签名是:
Period.getPeriodIdDay(int, oracle.sql.Date, oracle.sql.Date) return int但是java类本身中的metho的签名是:
int getPeriodIdDay(int multiplicity, DATE startDate, DATE date)如果在这里复制DATE的资本化是正确的,那么这是另一种类型。
即使这是一个复制错误:与java类的导入检查是否使用了相同的Date类。
发布于 2017-01-11 11:12:10
问题似乎是DATE类,我建议您使用字符串代替
您最好像这样更改您的方法类:
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);
}
}https://stackoverflow.com/questions/41589203
复制相似问题