JAVA에서 ORACLE로 배열넘기기

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

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

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

제가 능력많아..떡하니 이렇게 작품을 내놓으면 좋겠지만......
애석하게도.. 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,733
17년 전 조회 2,325
17년 전 조회 2,407
17년 전 조회 1,415
17년 전 조회 1,159
17년 전 조회 2,430
17년 전 조회 2,855
17년 전 조회 3,222
17년 전 조회 3,161
17년 전 조회 2,321
17년 전 조회 3,744
17년 전 조회 3,167
17년 전 조회 5,492
17년 전 조회 2,647
17년 전 조회 1,851
17년 전 조회 1,927
17년 전 조회 1,761
17년 전 조회 1,699
17년 전 조회 2,757
17년 전 조회 1,880
17년 전 조회 1,563
17년 전 조회 2,059
17년 전 조회 1,124
17년 전 조회 1,656
17년 전 조회 2,867
17년 전 조회 2,113
17년 전 조회 1,804
17년 전 조회 2,022
17년 전 조회 1,315
17년 전 조회 1,705
17년 전 조회 1,209
17년 전 조회 1,767
17년 전 조회 1,786
17년 전 조회 1,035
17년 전 조회 3,136
17년 전 조회 4,310
17년 전 조회 2,456
17년 전 조회 7,458
17년 전 조회 3,821
17년 전 조회 4,153
17년 전 조회 2,414
17년 전 조회 2,878
17년 전 조회 3,624
17년 전 조회 3,994
17년 전 조회 3,154
17년 전 조회 3,139
17년 전 조회 3,285
17년 전 조회 2,458
17년 전 조회 2,052
17년 전 조회 3,099
17년 전 조회 3,243
17년 전 조회 4,605
17년 전 조회 1,579
17년 전 조회 2,612
17년 전 조회 2,685
17년 전 조회 1,896
17년 전 조회 2,213
17년 전 조회 1,828
17년 전 조회 2,363
17년 전 조회 3,768
17년 전 조회 3,879
17년 전 조회 2,078
17년 전 조회 1,355
17년 전 조회 1,493
17년 전 조회 1,635
17년 전 조회 1,616
17년 전 조회 1,379
17년 전 조회 1,521
17년 전 조회 1,340
17년 전 조회 1,826
17년 전 조회 2,734
17년 전 조회 1,834
17년 전 조회 1,383
17년 전 조회 1,671
17년 전 조회 2,320
17년 전 조회 1,941
17년 전 조회 1,257
17년 전 조회 5,890
17년 전 조회 3,274
17년 전 조회 3,173
17년 전 조회 2,591
17년 전 조회 2,770
17년 전 조회 2,721
17년 전 조회 3,222
17년 전 조회 2,349
17년 전 조회 2,465
17년 전 조회 2,528
17년 전 조회 2,519
17년 전 조회 2,656
17년 전 조회 3,185
17년 전 조회 2,688
17년 전 조회 1,426
17년 전 조회 2,843
17년 전 조회 1,586
17년 전 조회 1,339
17년 전 조회 2,007
17년 전 조회 1,458
17년 전 조회 1,395
17년 전 조회 1,337
17년 전 조회 1,551
🐛 버그신고