简体   繁体   English

Java 存储过程或用户定义 function 无法调用 Java 方法

[英]Java stored procedure or user-defined function could not call Java method

After I created a Java external stored procedure in DB2 as in my previous question , the call在我之前的问题中,在 DB2 中创建了一个 Java 外部存储过程之后,调用

call user1.send_mail(
   P_TO          => 'me@domain.com'
  ,P_CC          => NULL
  ,P_BCC         => NULL
  ,P_FROM        => 'me@domain.com'
  ,P_SUBJECT     => 'db2 java subject'
  ,P_TEXT_MSG    => 'db2 java test'
  ,P_HTML_MSG    => null
  ,P_ATTACH_NAME => null
  ,P_ATTACH_MIME => null
  ,P_ATTACH_BLOB => null
  ,P_SMTP_HOST   => 'domain.com'
  ,P_SMTP_PORT   => 465
  ,P_USER_NAME   => 'me@domain.com'
  ,P_PASSWORD    => 'secret');

fails it due to the following error:由于以下错误而失败:

Java stored procedure or user-defined function "USER1.SEND_MAIL", specific name "SQL201208113215436" could not call Java method "send_mail", signature "(Ljava/lang/String".. SQLCODE=-4306, SQLSTATE=42724, DRIVER=3.68.61 Java 存储过程或用户定义 function “USER1.SEND_MAIL”,具体名称“SQL201208113215436”无法调用 Java 方法“send_mail”,签名“(Ljava/lang/String”.. SQLCODE=-4306, SQLSTATE=42724, DRIVER= 3.68.61

I made sure that all parameters that have no default values receive non- NULL values.我确保所有没有默认值的参数都收到非NULL值。 What else is necessary for this to work?这还需要什么?

Update:更新:

The db2diag.log file contains the following error message that I formatted for readability: db2diag.log文件包含以下错误消息,为了便于阅读,我对其进行了格式化:

MESSAGE : java.lang.NoSuchMethodError: 
db2/smtp.send_mail(
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
Ljava/sql/Blob;
Ljava/lang/String;
ILjava/lang/String;
Ljava/lang/String;)V

It is clear that the integer P_SMTP_PORT parameter of the Java method is missing between the 2nd and 3d last lines.很明显,Java 方法的 integer P_SMTP_PORT参数在第 2 行和 3d 最后一行之间丢失。 It looks like it has been totally skipped, even though my SQL call includes this parameter.看起来它已被完全跳过,即使我的 SQL 调用包含此参数。 What does this mean?这是什么意思? Also, what is the significance of the extra I in front of Ljava on the 2nd last line?另外,最后一行第二行Ljava前面的额外I有什么意义?

The JAR file is being registered from a C# application, using the following code:正在使用以下代码从 C# 应用程序注册 JAR 文件:

using (var cmd = conn.CreateCommand())
{
    cmd.CommandText = "sqlj.db2_install_jar";
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("blob", DB2Type.Blob).Value = File.ReadAllBytes(args[4]);
    cmd.Parameters.Add("jarname", DB2Type.VarChar, 257).Value = "javadb2";
    cmd.Parameters.Add("deploy", DB2Type.Integer).Value = 0;
    cmd.ExecuteNonQuery();

    cmd.Parameters.Clear();
    cmd.CommandText = "SQLJ.REFRESH_CLASSES";
    cmd.ExecuteNonQuery();
}

I checked and made sure that the JAR file correctly trickles down to C:\ProgramData\IBM\DB2\DB2COPY1\function\jar\USER1\JAVADB2.jar after the code above runs, and that it is still in the correct format.我检查并确保 JAR 文件在上面的代码运行后正确地下降到C:\ProgramData\IBM\DB2\DB2COPY1\function\jar\USER1\JAVADB2.jar

As per Table 17. SQL Data Types Mapped to Java Declarations on p.根据表17。SQL 数据类型映射到第 Java页的声明。 241 of IBM DB2 10.5 for Linux, UNIX, and Windows Developing User-defined Routines (SQL and External) , BLOB SQL data type maps to java.sql.Blob Java data type, not to byte[] that I had initially. 241 of IBM DB2 10.5 for Linux, UNIX, and Windows Developing User-defined Routines (SQL and External) , BLOB SQL data type maps to java.sql.Blob Java data type, not to byte[] that I had initially.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在java中调用包含用户定义类型的oracle存储过程? - How to call oracle stored procedure which include user-defined type in java? 创建一个创建用户定义函数的存储过程是否是一种好习惯……? - Is it a good practice to create a stored procedure that creates a user-defined function…? 将用户定义的表传递给存储过程 - Pass A User-Defined Table to a Stored Procedure 是否可以在用户定义的函数中调用存储过程? - Is it possible to call a stored procedure in a user defined function ? 存储过程:多次使用用户定义的变量或调用数据库函数 - Stored Procedure: Use User-Defined Variable or Call Database functions multiple times 在存储过程mariaDB中使用select设置用户定义的变量 - Setting user-defined variable with select in stored procedure mariaDB SQL用户定义函数与存储过程分支 - SQL user-defined functions vs. stored procedure branching C#:将用户定义的类型传递给Oracle存储过程 - C#: Pass a user-defined type to a Oracle stored procedure 在“in”子句的存储过程中使用 MySQL 用户定义的变量 - Using MySQL user-defined variable in stored procedure for 'in' clause 在存储过程中插入或更新用户定义的表类型 - Insert or Update user-defined table type in a stored procedure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM