oracle bulk load

First create types in oracle
DROP TYPE CINBELLINP.D_TABLE;

CREATE OR REPLACE TYPE CINBELLINP.d_table is table of Date;
/

DROP TYPE CINBELLINP.I_TABLE;

CREATE OR REPLACE TYPE CINBELLINP.i_table is table of number(10);
/

DROP TYPE CINBELLINP.V_TABLE;

CREATE OR REPLACE TYPE CINBELLINP.v_table is table of varchar2(10);
/


second, create procedure

CREATE OR REPLACE procedure CINBELLINP.pro_forall_insert(v_1 i_table,v_2 v_table, v_3 d_table)
as
begin

forall i in 1.. v_1.count
insert into a values(v_1(i),v_2(i), v_3(i));
end;
/


in java side call

package com.whatever

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Date;

import oracle.sql.ARRAY;


public class testOracle {
public testOracle() {

Connection oraCon = null;
try {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
}
catch (ClassNotFoundException ex)
{}
oraCon = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.1:1521:Test", "test","test");
oraCon.setAutoCommit(false);
} catch (SQLException ex) {
ex.printStackTrace();
}
System.out.println("now");

CallableStatement cstmt = null;
oracle.sql.ArrayDescriptor a = null;
oracle.sql.ArrayDescriptor b = null;
oracle.sql.ArrayDescriptor c = null;
java.util.Date datetime=new java.util.Date();
java.sql.Date mySqlDate = new java.sql.Date(datetime.getTime());
if (true )
{
Object[] s1 = new Object[1000000];
Object[] s2 = new Object[1000000];
Object[] s3 = new Object[1000000];

for (int i = 0; i < 1000000; i++) {
s1[i] = new Integer(1);
s2[i] = new String("aaa").concat(String.valueOf(i));
s3[i] = mySqlDate;
}
try {
a = oracle.sql.ArrayDescriptor.createDescriptor("I_TABLE", oraCon);
b = oracle.sql.ArrayDescriptor.createDescriptor("V_TABLE", oraCon);
c = oracle.sql.ArrayDescriptor.createDescriptor("D_TABLE", oraCon);
ARRAY a_test = new ARRAY(a, oraCon, s1);
ARRAY b_test = new ARRAY(b, oraCon, s2);
ARRAY c_test = new ARRAY(c, oraCon, s3);
cstmt = oraCon.prepareCall("{ call pro_forall_insert(?,?,?) }");
cstmt.setObject(1, a_test);
cstmt.setObject(2, b_test);
cstmt.setObject(3, c_test);
long aaaa = System.currentTimeMillis();
System.out.println(System.currentTimeMillis());
cstmt.execute();
oraCon.commit();
System.out.println("now");
System.out.println(System.currentTimeMillis()-aaaa);
}
catch (Exception e) {
e.printStackTrace();
}
}
try{
PreparedStatement oraPs = null;
String oraInsertSql =
"insert into a values(?,?,?)";

oraPs = oraCon.prepareStatement(oraInsertSql);
long aaaa = System.currentTimeMillis();
System.out.println(System.currentTimeMillis());
datetime=new java.util.Date();
mySqlDate = new java.sql.Date(datetime.getTime());
for (int i = 0; i < 1000000; i++)
{
oraPs.setInt(1,i);
oraPs.setString(2, new String("aaa").concat(String.valueOf(i)));
oraPs.setDate(3, mySqlDate);
oraPs.executeUpdate();
}
oraCon.commit();
System.out.println(System.currentTimeMillis()-aaaa);
}
catch (SQLException ex)
{
System.out.print("dddddd");
System.out.print(ex.getMessage());
}
try {
System.out.println("finished");
jbInit();
}
catch (Exception ex) {
ex.printStackTrace();
}
}


public static void main(String args[]) {
testOracle a = new testOracle();
}

private void jbInit() throws Exception {
}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值