[英]Java method not found running on oracle database
I have can not deal with execute my java method on oracle server. 我无法处理在oracle服务器上执行我的java方法。 I load my java class on database using loadjava and create function using this query: 我使用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';
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: 函数声明中java方法的签名为:
Period.getPeriodIdDay(int, oracle.sql.Date, oracle.sql.Date) return int
but the signatur of the metho in the java class itself is: 但是java类本身的方法的特征是:
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. 如果在此处复制DATE
的大写字母没有错,那么这是另一种类型。
And even if it is a copy mistake: check with the imports of the java class that the same Date
class is used. 即使是复制错误,也请执行以下操作:检查java类的导入是否使用了相同的Date
类。
the problem seems to be the DATE class, I suggest you to use String instead 问题似乎是DATE类,建议您改用String
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.