JAVA에서 ORACLE로 배열넘기기

· 17년 전 · 3108
오라클과 프로그램간에 배열을 어떻게 주고 받을 것이지
고민해 보신 분들이 계실 줄 압니다.

며칠간 시간이 나서 이리저리 찾아보니까..다음처럼 결과물이 나왔네요...
사실 몇 달 전부터 한 번 봐야 쓰겄다 했는데...이제사 조금 감을 잡았습니다.
실제적으로 프로젝트에 적용해본 적은 없고..테스트로 해 본 내용입니다.

필요한 상황에 맞게 응용을 해보시면 될 성 싶습니다.

제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. http://asktom.oracle.com/pls/ask/f?p=4950:1:  에서 자료참조를 했습니다.


1. Java Stored Procedure "ArrayDemo" 생성

create or replace
and compile java source named "ArrayDemo"
as
    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
 
    public class ArrayDemo
    {
       public static void passArray() throws SQLException
       {
           Connection conn = new OracleDriver().defaultConnection();
 
           int intArray[] = { 1,2,3,4,5,6 };
 
           ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor( "NUM_ARRAY",
conn);
           ARRAY array_to_pass = new ARRAY( descriptor, conn, intArray );
 
           OraclePreparedStatement ps =
                 (OraclePreparedStatement)conn.prepareStatement( "begin give_me_an_array
(:x); end;" );
           ps.setARRAY( 1, array_to_pass );
           ps.execute();
       }
    }
/

Java created.


2. 사용할 Array(or TYPE) 생성
create or replace type NUM_ARRAY as table of number;
/

Type created.


3. Array 출력시키는 Procedure 생성
create or replace procedure give_me_an_array( p_array in num_array )
as
begin
    for i in 1 .. p_array.count
    loop
      dbms_output.put_line( p_array(i) );
      end loop;
    end;
/

Procedure created.


4. java source를 호출하는 Procedure 생성
create or replace procedure show_java_calling_plsql
as language java
name 'ArrayDemo.passArray()';
/

Procedure created.


5. Procedure "give_me_an_array"에서 출력하는 내용을 보기 위한 명령어
set serveroutput on


6. show_java_calling_plsql 실행
exec show_java_calling_plsql

결과>
1
2
3
4
5
6
[이 게시물은 관리자님에 의해 2011-10-31 16:47:36 Oracle에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
17년 전 조회 1,739
17년 전 조회 2,334
17년 전 조회 2,416
17년 전 조회 1,421
17년 전 조회 1,167
17년 전 조회 2,438
17년 전 조회 2,862
17년 전 조회 3,228
17년 전 조회 3,168
17년 전 조회 2,329
17년 전 조회 3,751
17년 전 조회 3,172
17년 전 조회 5,500
17년 전 조회 2,655
17년 전 조회 1,859
17년 전 조회 1,933
17년 전 조회 1,771
17년 전 조회 1,709
17년 전 조회 2,766
17년 전 조회 1,889
17년 전 조회 1,571
17년 전 조회 2,066
17년 전 조회 1,130
17년 전 조회 1,664
17년 전 조회 2,874
17년 전 조회 2,118
17년 전 조회 1,812
17년 전 조회 2,028
17년 전 조회 1,321
17년 전 조회 1,710
17년 전 조회 1,220
17년 전 조회 1,771
17년 전 조회 1,792
17년 전 조회 1,041
17년 전 조회 3,142
17년 전 조회 4,317
17년 전 조회 2,463
17년 전 조회 7,465
17년 전 조회 3,828
17년 전 조회 4,159
17년 전 조회 2,422
17년 전 조회 2,887
17년 전 조회 3,629
17년 전 조회 4,001
17년 전 조회 3,159
17년 전 조회 3,146
17년 전 조회 3,291
17년 전 조회 2,463
17년 전 조회 2,060
17년 전 조회 3,109
17년 전 조회 3,250
17년 전 조회 4,613
17년 전 조회 1,587
17년 전 조회 2,617
17년 전 조회 2,691
17년 전 조회 1,903
17년 전 조회 2,220
17년 전 조회 1,834
17년 전 조회 2,369
17년 전 조회 3,776
17년 전 조회 3,886
17년 전 조회 2,085
17년 전 조회 1,359
17년 전 조회 1,500
17년 전 조회 1,641
17년 전 조회 1,623
17년 전 조회 1,384
17년 전 조회 1,528
17년 전 조회 1,349
17년 전 조회 1,832
17년 전 조회 2,742
17년 전 조회 1,840
17년 전 조회 1,388
17년 전 조회 1,680
17년 전 조회 2,328
17년 전 조회 1,948
17년 전 조회 1,262
17년 전 조회 5,900
17년 전 조회 3,284
17년 전 조회 3,182
17년 전 조회 2,597
17년 전 조회 2,778
17년 전 조회 2,728
17년 전 조회 3,230
17년 전 조회 2,356
17년 전 조회 2,473
17년 전 조회 2,534
17년 전 조회 2,525
17년 전 조회 2,664
17년 전 조회 3,194
17년 전 조회 2,696
17년 전 조회 1,433
17년 전 조회 2,848
17년 전 조회 1,591
17년 전 조회 1,344
17년 전 조회 2,013
17년 전 조회 1,465
17년 전 조회 1,403
17년 전 조회 1,344
17년 전 조회 1,558
🐛 버그신고