JAVA에서 ORACLE로 배열넘기기

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

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

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

제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. 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,760
17년 전 조회 2,354
17년 전 조회 2,444
17년 전 조회 1,440
17년 전 조회 1,192
17년 전 조회 2,462
17년 전 조회 2,884
17년 전 조회 3,256
17년 전 조회 3,194
17년 전 조회 2,355
17년 전 조회 3,775
17년 전 조회 3,196
17년 전 조회 5,523
17년 전 조회 2,679
17년 전 조회 1,883
17년 전 조회 1,957
17년 전 조회 1,795
17년 전 조회 1,732
17년 전 조회 2,791
17년 전 조회 1,910
17년 전 조회 1,593
17년 전 조회 2,092
17년 전 조회 1,147
17년 전 조회 1,691
17년 전 조회 2,899
17년 전 조회 2,148
17년 전 조회 1,833
17년 전 조회 2,047
17년 전 조회 1,345
17년 전 조회 1,728
17년 전 조회 1,241
17년 전 조회 1,796
17년 전 조회 1,809
17년 전 조회 1,064
17년 전 조회 3,162
17년 전 조회 4,339
17년 전 조회 2,481
17년 전 조회 7,492
17년 전 조회 3,844
17년 전 조회 4,182
17년 전 조회 2,444
17년 전 조회 2,909
17년 전 조회 3,650
17년 전 조회 4,023
17년 전 조회 3,179
17년 전 조회 3,169
17년 전 조회 3,322
17년 전 조회 2,483
17년 전 조회 2,084
17년 전 조회 3,127
17년 전 조회 3,273
17년 전 조회 4,633
17년 전 조회 1,602
17년 전 조회 2,638
17년 전 조회 2,711
17년 전 조회 1,926
17년 전 조회 2,237
17년 전 조회 1,859
17년 전 조회 2,398
17년 전 조회 3,794
17년 전 조회 3,911
17년 전 조회 2,107
17년 전 조회 1,383
17년 전 조회 1,518
17년 전 조회 1,655
17년 전 조회 1,634
17년 전 조회 1,400
17년 전 조회 1,545
17년 전 조회 1,364
17년 전 조회 1,851
17년 전 조회 2,769
17년 전 조회 1,857
17년 전 조회 1,410
17년 전 조회 1,701
17년 전 조회 2,347
17년 전 조회 1,969
17년 전 조회 1,278
17년 전 조회 5,919
17년 전 조회 3,309
17년 전 조회 3,201
17년 전 조회 2,621
17년 전 조회 2,799
17년 전 조회 2,747
17년 전 조회 3,250
17년 전 조회 2,379
17년 전 조회 2,494
17년 전 조회 2,559
17년 전 조회 2,546
17년 전 조회 2,684
17년 전 조회 3,216
17년 전 조회 2,720
17년 전 조회 1,456
17년 전 조회 2,870
17년 전 조회 1,617
17년 전 조회 1,360
17년 전 조회 2,031
17년 전 조회 1,487
17년 전 조회 1,422
17년 전 조회 1,360
17년 전 조회 1,581