存储过程的错误
test1表结构ID NUMBER(10)
DESCRIPTION VARCHAR2(50)
测试过程
type t_id is table of test1.id%type index by binary_integer;
type t_description is table of test1.description%type index by binary_integer;
procedure test(tid out t_id, tdescription out t_description) is
begin
select id, description bulk collect into tid, tdescription from test1;
end;
JAVA中是这样写的[因为是TEST,比较简陋]
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import oracle.jdbc.internal.OracleTypes;
public class test{
public static void main(String str[]){
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;
try{
Class.forName("racle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thinlocalhost:1521:test","test","test");
CallableStatement call=conn.prepareCall("{call test.test(?,?)}");
call.registerOutParameter(1,OracleTypes.PLSQL_INDEX_TABLE);
call.registerOutParameter(2,OracleTypes.PLSQL_INDEX_TABLE);
call.execute();
}catch(Exception e){
System.out.println(e); }}}
但是发生了java.sql.SQLException: ORA-03115: 不支持的网络数据类型或表示法.
数据库是 Oracle9i Enterprise Edition Release 9.2.0.1.0 ;1.4JDK;JDBC驱动是FOR ORACLE 9.2.0.1
我以为是JDBC驱动问题,于是换用了以下两个版本的:
JDBC驱动是FOR ORACLE 8.1.7 还是报出java.sql.SQLException: ORA-03115: 不支持的网络数据类型或表示法.
JDBC驱动是FOR ORACLE 10G的却报出java.sql.SQLException: 索引中丢失 IN 或 OUT 参数:: 1
的错误.
请大家帮忙看看,到底是错在什么地方拉?
存储过程返回参数是OracleTypes.PLSQL_INDEX_TABLE 的,需要什么特别处理吗?
斑竹能来看看给个意见吗? 包头:
create or replace package test is
type t_id is table of test1.id%type index by binary_integer;
type t_description is table of test1.description%type index by binary_integer;
type t1 is table of number(10) index by binary_integer;
procedure test(tid out t_id, tdescription out t_description);
procedure testtest(tid out t_id);
end test;
包体:
create or replace package body test is
procedure test(tid out t_id, tdescription out t_description) is
begin
select id, description bulk collect into tid, tdescription from test1;
end;
procedure testtest(tid out t_id) is
begin
for i in 1 .. 1000000 loop
tid(i) := i;
end loop;
end;
end test;
JAVA源码:
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import oracle.jdbc.internal.OracleTypes;
public class test{
public static void main(String str[]){
Connection conn=null;
PreparedStatement pst=null;
ResultSet rs=null;
try{
Class.forName("racle.jdbc.driver.OracleDriver");
conn=DriverManager.getConnection("jdbc:oracle:thinlocalhost:1521:test","test","test");
CallableStatement call=conn.prepareCall("{call test.test(?,?)}");
call.registerOutParameter(1,OracleTypes.PLSQL_INDEX_TABLE);
call.registerOutParameter(2,OracleTypes.PLSQL_INDEX_TABLE);
call.execute();
}catch(Exception e){
System.out.println(e); }}}
页:
[1]