JAVA에서 ORACLE로 배열넘기기

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

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

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

제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. 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,812
17년 전 조회 2,428
17년 전 조회 2,505
17년 전 조회 1,505
17년 전 조회 1,258
17년 전 조회 2,519
17년 전 조회 2,949
17년 전 조회 3,322
17년 전 조회 3,266
17년 전 조회 2,425
17년 전 조회 3,846
17년 전 조회 3,276
17년 전 조회 5,588
17년 전 조회 2,754
17년 전 조회 1,954
17년 전 조회 2,029
17년 전 조회 1,866
17년 전 조회 1,799
17년 전 조회 2,861
17년 전 조회 1,982
17년 전 조회 1,655
17년 전 조회 2,161
17년 전 조회 1,205
17년 전 조회 1,758
17년 전 조회 2,968
17년 전 조회 2,210
17년 전 조회 1,895
17년 전 조회 2,119
17년 전 조회 1,419
17년 전 조회 1,805
17년 전 조회 1,314
17년 전 조회 1,864
17년 전 조회 1,877
17년 전 조회 1,127
17년 전 조회 3,235
17년 전 조회 4,411
17년 전 조회 2,558
17년 전 조회 7,566
17년 전 조회 3,920
17년 전 조회 4,251
17년 전 조회 2,507
17년 전 조회 2,987
17년 전 조회 3,728
17년 전 조회 4,089
17년 전 조회 3,245
17년 전 조회 3,239
17년 전 조회 3,393
17년 전 조회 2,552
17년 전 조회 2,146
17년 전 조회 3,192
17년 전 조회 3,359
17년 전 조회 4,691
17년 전 조회 1,677
17년 전 조회 2,704
17년 전 조회 2,784
17년 전 조회 1,991
17년 전 조회 2,304
17년 전 조회 1,919
17년 전 조회 2,471
17년 전 조회 3,867
17년 전 조회 3,974
17년 전 조회 2,176
17년 전 조회 1,437
17년 전 조회 1,572
17년 전 조회 1,720
17년 전 조회 1,700
17년 전 조회 1,467
17년 전 조회 1,608
17년 전 조회 1,419
17년 전 조회 1,916
17년 전 조회 2,825
17년 전 조회 1,919
17년 전 조회 1,477
17년 전 조회 1,779
17년 전 조회 2,412
17년 전 조회 2,042
17년 전 조회 1,338
17년 전 조회 5,989
17년 전 조회 3,366
17년 전 조회 3,272
17년 전 조회 2,673
17년 전 조회 2,864
17년 전 조회 2,817
17년 전 조회 3,317
17년 전 조회 2,443
17년 전 조회 2,563
17년 전 조회 2,623
17년 전 조회 2,618
17년 전 조회 2,742
17년 전 조회 3,291
17년 전 조회 2,782
17년 전 조회 1,522
17년 전 조회 2,939
17년 전 조회 1,678
17년 전 조회 1,431
17년 전 조회 2,098
17년 전 조회 1,553
17년 전 조회 1,486
17년 전 조회 1,426
17년 전 조회 1,638