我試圖通過java調用我的oracle 11g pl/sql包它會報錯。請幫幫我。 這是關於pl/sql程序,java程序和Java錯誤的所有信息。如何調用我的程序編譯錯誤發生在java
過程成功創建和sql查詢都經過測試。
/*
* create package called "final_package"
* create PROCEDURE called "final_procedure"
* var1 is input parameter from application
* dbinfo is out parameter to application
*/
CREATE OR REPLACE PACKAGE final_package as
PROCEDURE final_procedure(var1 in varchar2, dbinfo out varchar2);
END final_package;
/
CREATE OR REPLACE PACKAGE BODY final_package IS
PROCEDURE final_procedure(var1 in varchar2, dbinfo out varchar2) IS
BEGIN
IF var1 = 'a' --input variable checking--
------ /* get tablespaces name, percentage */ ----
THEN
DECLARE
tsname varchar2(500); ---- /* put tablespaces name to this tsinfo */----
percentage varchar2(500); ---- /* put tablespaces percentage to this tsinfo */----
--declare cursor tbspinfo--
CURSOR tbspinfo is select a.TABLESPACE_NAME as
Tablespace,round((1-((a.BYTES-nvl(b.BYTES,0))/a.BYTES))*100,2)
AS
Percentages from (select TABLESPACE_NAME, sum(BYTES) BYTES from
sys.dba_data_files group by TABLESPACE_NAME) a,
(select
TABLESPACE_NAME, sum(BYTES) BYTES from sys.dba_free_space
group by
TABLESPACE_NAME) b
where
a.TABLESPACE_NAME = b.TABLESPACE_NAME (+)
order by ((a.BYTES-b.BYTES)/a.BYTES) desc;
BEGIN
FOR each_data1 in tbspinfo
LOOP
-- FETCH tsname,percentage INTO tsinfo ---
FETCH tbspinfo INTO tsname, percentage;
-- add tsinfo INTO out parameter "dbinfo" ---
dbinfo := tsname || percentage;
END LOOP;
CLOSE tbspinfo;
END;
---- /* get database lock status */ ----
ELSIF var1 = 'b' THEN
DECLARE
locking_id varchar2(1500);
waiting_id varchar2(1500);
status varchar2(150);
program_hold varchar2(300);
program_wait varchar2(300);
--declare cursor lock_info--
CURSOR lock_info is SELECT vh.sid locking_sid,
vw.sid waiter_sid,
vs.status status,
vs.program program_holding,
vsw.program program_waiting
FROM v$lock vh,
v$lock vw,
v$session vs,
v$session vsw
WHERE(vh.id1, vh.id2) IN (SELECT id1, id2
FROM v$lock
WHERE request = 0
INTERSECT
SELECT id1, id2
FROM v$lock
WHERE lmode = 0)
AND vh.id1 = vw.id1
AND vh.id2 = vw.id2
AND vh.request = 0
AND vw.lmode = 0
AND vh.sid = vs.sid
AND vw.sid = vsw.sid;
BEGIN
FOR each_data in lock_info
LOOP
-- /* put database lock_info to varchar2 variables "locking_id,waiting_id,status,program_hold,program_wait" */ --
FETCH lock_info INTO locking_id,waiting_id,status,program_hold,program_wait;
END LOOP;
CLOSE lock_info;
-- /* add lock_info INTO out parameter "dbinfo" */ ---
dbinfo := locking_id || waiting_id || status || program_hold || program_wait;
END;
END IF;
END;
END;
/
java代碼是
CallableStatement clbstmt = con.prepareCall("BEGIN final_package.final_procedure(?,?); END;");
clbstmt.setString(1, var1);
clbstmt.registerOutParameter(2, OracleTypes.VARCHAR);
clbstmt.execute(); // error comes at this
abc = clbstmt.getNString(Integer.SIZE);
abb = clbstmt.getNString(Integer.SIZE);
Java錯誤是
SEVERE: null
java.sql.SQLException: ORA-01001: invalid cursor
ORA-06512: at "SYS.FINAL_PACKAGE", line 71
說明您的問題簡單?把所需的代碼和java stacktrace?如果不知道問題,你的整個程序代碼就沒有意義了? java錯誤/代碼鏈接不起作用 –
你的'con.prepareCall'有問題。只需放入package.procedurename,它將調用所需的過程。你不需要添加'BEGIN'和'END'。 – Rachcha
@ Rachcha我檢查並更改,但錯誤是一樣的。我認爲程序錯誤。我對pl/sql代碼做了一點點評論,請幫助我 –