日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle insert 数组,oracle 数组 批量insert

發(fā)布時間:2024/10/12 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle insert 数组,oracle 数组 批量insert 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

場景:[轉(zhuǎn)]jdbc批量insert———oracle數(shù)組類型與forall的使用

[轉(zhuǎn)]jdbc批量insert———oracle數(shù)組類型與forall的應(yīng)用

原文:http://blog.itpub.net/post/37572/465011

測試java的insert 同使用9i以后的bulk Insert 的速度.

測試結(jié)果顯示通過bulk Insert 速度相當(dāng)?shù)目?

100000條記錄

insert ,---------------93秒

bulk insert -------------0.441秒

環(huán)境:

oracle 10.2.0.3 Windows 2000Server

java

代碼:

SQL> desc a

Name Type Nullable Default Comments

---- ------------ -------- ------- --------

ID INTEGER Y

NAME VARCHAR2(20) Y

bulk Insert 使用的類型及過程

create or replace type i_table is table of number(10);

create or replace type v_table is table of varchar2(10);

create or replace procedure pro_forall_insert(v_1 i_table,v_2 v_table)

as

c integer;

begin

forall i in 1.. v_1.count

insert into a values(v_1(i),v_2(i));

end;

測試的java代碼:

import java.io.*;

import java.sql.*;

import java.util.*;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.*;

import oracle.jdbc.OracleTypes;

import oracle.sql.*;

import oracle.sql.ARRAY;

import oracle.sql.ArrayDescriptor;

import oracle.sql.STRUCT;

import oracle.sql.StructDescriptor;

import java.sql.Connection;

import java.sql.DriverManager;

import oracle.jdbc.OracleCallableStatement;

public class testOracle

{

public testOracle()

{

Connection oraCon = null;

PreparedStatement ps = null;

Statement st = null;

ResultSet rs = null;

try

{

try

{

Class.forName("oracle.jdbc.driver.OracleDriver");

}

catch (ClassNotFoundException ex)

{

}

oraCon = DriverManager.getConnection("jdbc:oracle:thin:@192.168.15.234:1521:ora10g",

"imcs",

"imcs");

oraCon.setAutoCommit(false);

}

catch (SQLException ex)

{

ex.printStackTrace();

}

CallableStatement cstmt = null;

oracle.sql.ArrayDescriptor a = null;

oracle.sql.ArrayDescriptor b = null;

if (1 == 1)

{

Object[] s1 = new Object[100000];

Object[] s2 = new Object[100000];

for (int i = 0; i < 100000; i++)

{

s1[i] = new Integer(1);

s2[i] = new String("aaa").concat(String.valueOf(i));

}

try

{

a = oracle.sql.ArrayDescriptor.createDescriptor("I_TABLE",

oraCon);

b = oracle.sql.ArrayDescriptor.createDescriptor("V_TABLE",

oraCon);

ARRAY a_test = new ARRAY(a, oraCon, s1);

ARRAY b_test = new ARRAY(b, oraCon, s2);

cstmt = oraCon.prepareCall("{ call pro_forall_insert(?,?) }");

cstmt.setObject(1, a_test);

cstmt.setObject(2, b_test);

long aaaa = System.currentTimeMillis();

System.out.println(System.currentTimeMillis());

cstmt.execute();

oraCon.commit();

System.out.println(System.currentTimeMillis() - aaaa);

}

catch (Exception e)

{

e.printStackTrace();

}

}

else

{

try

{

PreparedStatement oraPs = null;

String oraInsertSql = "insert into a values(?,?)";

oraPs = oraCon.prepareStatement(oraInsertSql);

long aaaa = System.currentTimeMillis();

System.out.println(System.currentTimeMillis());

for (int i = 0; i < 100000; i++)

{

oraPs.setInt(1, i);

oraPs.setString(2,

new String("aaa").concat(String.valueOf(i)));

oraPs.executeUpdate();

}

oraCon.commit();

System.out.println(System.currentTimeMillis() - aaaa);

}

catch (SQLException ex)

{

System.out.print("dddddd");

System.out.print(ex.getMessage());

}

}

try

{

jbInit();

}

catch (Exception ex)

{

ex.printStackTrace();

}

}

public static void main(String args[])

{

testOracle a = new testOracle();

}

private void jbInit() throws Exception

{

}

};

總結(jié)

以上是生活随笔為你收集整理的oracle insert 数组,oracle 数组 批量insert的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。