日期:2014-05-17 浏览次数:20873 次
SQL> desc aa
Name Null? Type
----------------------------------------- -------- ---------------------
NAME VARCHAR2(10)
SQL> truncate table aa;
Table truncated.
SQL> select * from aa;
no rows selected
SQL>
create or replace type ARR as table of VARCHAR2(200) NOT NULL;
/
create or replace procedure give_me_an_array(myArray arr)
as
begin
forall i in myArray.first..myArray.last
insert into aa values(myArray(i));
COMMIT;
end;
/
import java.sql.*;
import java.util.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
public class test
{
public static void main(String args[]) throws Exception
{
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection(
"jdbc.oracle:thin:@192.168.1.1:1521:orcl","username","password");
String a[]={"3","2","abc"};
ArrayDescriptor descriptor = ArrayDescriptor.createDescriptor("ARR",conn);
ARRAY array_to_pass = new ARRAY(descriptor,conn,a);
OraclePreparedStatement ps = (OraclePreparedStatement)conn.prepareStatement
("begin give_me_an_array(:x); end;");
ps.setARRAY( 1, array_to_pass );
ps.execute();
}
}
e:javac test.java
e:java test
SQL> select * from aa;
NAME
----------
3
2
abc
3 rows selected.
------解决方案--------------------
http://topic.csdn.net/u/20100310/15/7f83d565-4406-4193-9e09-5738a98745d8.html