我试图通过 java 调用我的 oracle 11g pl/sql 包它出错。请帮帮我。这是有关 pl/sql 过程、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