gpt4 book ai didi

java - 在Java代码中调用Oracle过程

转载 作者:行者123 更新时间:2023-11-30 07:44:43 25 4
gpt4 key购买 nike

我尝试在 Java 代码中调用此过程:

create or replace procedure statistics_function
( namein in varchar2
, lob_out out nocopy clob )
is
cursor last_60_cpu_cursor is
select 1 as last_60_cpu, sysdate as last_60_event_date
from dual
;
begin
dbms_lob.createtemporary(lob_loc => lob_out, cache => true, dur => dbms_lob.session);

for cv in last_60_cpu_cursor loop
dbms_lob.append(lob_out, to_char(cv.last_60_event_date)||'i'||to_char(cv.last_60_cpu)||chr(10));
end loop;

dbms_lob.append(lob_out, 'last_60_cpu'||chr(10)||chr(10));
end statistics_function;

Java代码:

public static void main(String Args[]) throws SQLException
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@31.187.70.163:1521:xe", "admin", "qwerty");

CallableStatement cstmt = conn.prepareCall("statistics_function(?, ?); end;");

cstmt.registerOutParameter(2, Types.VARCHAR);
cstmt.setString(1, "agent");

cstmt.execute();
String result = cstmt.getString(1);
conn.close();
System.out.println(result);
}

我收到此错误:

Exception in thread "main" java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement 

你能帮我解决这个问题吗?我想我的Java代码有一些错误?

您能为这个问题提出一些解决方案吗?

最佳答案

您的语法错误:试试这个:

CallableStatement cstmt = conn.prepareCall("{ 调用statistics_function(?, ?)}");

关于java - 在Java代码中调用Oracle过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34090030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com