import java.io.*;
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class ArrayDemo
{
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@210.102.97.18:1521:v880","ihjdbmgr", "ihjdbmgr01");
// Object objArray1[][] = {{"Ha"},{"Kweon"},{"Park"}};
Object objArray1[] = {"Ha1","12345678901231"};
Object objArray2[] = {"Ha2","12345678901232"};
Object objArray3[] = {"Ha3","12345678901233"};
Object objArray[] = new Object[3];
StructDescriptor desc1 = StructDescriptor.createDescriptor("STUD_BUFFER",conn);
ArrayDescriptor desc2 = ArrayDescriptor.createDescriptor( "STUD_ARRAY", conn);
STRUCT pstruct = null;
pstruct = new STRUCT(desc1, conn, objArray1);
objArray[0] = pstruct;
pstruct = new STRUCT(desc1, conn, objArray2);
objArray[1] = pstruct;
pstruct = new STRUCT(desc1, conn, objArray3);
objArray[2] = pstruct;
ARRAY array_to_pass = new ARRAY( desc2, conn, objArray );
/*
int i = 0;
for (i=0;i < 3 ;i++ )
{
System.out.println(i+" : "+array_to_pass[i].toString());
}
*/
System.out.println(array_to_pass.getOracleArray());
OraclePreparedStatement ps =
(OraclePreparedStatement)conn.prepareStatement
( "begin batchUpdate(:x,:x2,:x3); end;" );
ps.setARRAY( 1, array_to_pass ); // 처리될 배열
ps.setInt( 2, 3); // 처리될 개수
ps.setString( 3, "2003"); // 학년도
ps.execute();
}
}
/*
drop type STUD_BUFFER;
drop type STUD_ARRAY
-- update용 type선언
create or replace type STUD_BUFFER as object(sorted_rank varchar2(30), gupsu_no varchar2(10));
-- 실행
create or replace type STUD_ARRAY as table of STUD_BUFFER;
procedure give_me_an_array( p_array in num_array, p_count in number )
as
begin
for i in 1 .. p_count
loop
dbms_output.put_line(p_array(i).name);
insert into emp2(name) values (p_array(i).name);
commit;
end loop;
end;
*/
import java.sql.*;
import oracle.sql.*;
import oracle.jdbc.driver.*;
public class ArrayDemo
{
public static void main(String[] args) throws SQLException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@210.102.97.18:1521:v880","ihjdbmgr", "ihjdbmgr01");
// Object objArray1[][] = {{"Ha"},{"Kweon"},{"Park"}};
Object objArray1[] = {"Ha1","12345678901231"};
Object objArray2[] = {"Ha2","12345678901232"};
Object objArray3[] = {"Ha3","12345678901233"};
Object objArray[] = new Object[3];
StructDescriptor desc1 = StructDescriptor.createDescriptor("STUD_BUFFER",conn);
ArrayDescriptor desc2 = ArrayDescriptor.createDescriptor( "STUD_ARRAY", conn);
STRUCT pstruct = null;
pstruct = new STRUCT(desc1, conn, objArray1);
objArray[0] = pstruct;
pstruct = new STRUCT(desc1, conn, objArray2);
objArray[1] = pstruct;
pstruct = new STRUCT(desc1, conn, objArray3);
objArray[2] = pstruct;
ARRAY array_to_pass = new ARRAY( desc2, conn, objArray );
/*
int i = 0;
for (i=0;i < 3 ;i++ )
{
System.out.println(i+" : "+array_to_pass[i].toString());
}
*/
System.out.println(array_to_pass.getOracleArray());
OraclePreparedStatement ps =
(OraclePreparedStatement)conn.prepareStatement
( "begin batchUpdate(:x,:x2,:x3); end;" );
ps.setARRAY( 1, array_to_pass ); // 처리될 배열
ps.setInt( 2, 3); // 처리될 개수
ps.setString( 3, "2003"); // 학년도
ps.execute();
}
}
/*
drop type STUD_BUFFER;
drop type STUD_ARRAY
-- update용 type선언
create or replace type STUD_BUFFER as object(sorted_rank varchar2(30), gupsu_no varchar2(10));
-- 실행
create or replace type STUD_ARRAY as table of STUD_BUFFER;
procedure give_me_an_array( p_array in num_array, p_count in number )
as
begin
for i in 1 .. p_count
loop
dbms_output.put_line(p_array(i).name);
insert into emp2(name) values (p_array(i).name);
commit;
end loop;
end;
*/