java调用存储过程传number参数_java中调用存储过程并传递list集合参数的方法 | 学步园...

sql:

CREATE OR REPLACE TYPE test as object(

FID NUMBER,

NUM nVARCHAR2(30),TESKID NUMBER,

CID NUMBER,

USERCODE nVARCHAR2(100)

)

CREATE OR REPLACE TYPE test_list as table of test

CREATE OR REPLACE PROCEDURE inserttenumber(

v_rec_class_list    IN test_list)is

v_rec_class test;

v_count number;

begin

v_count := v_rec_class_list.count;

for i in 1..v_count

loop

v_rec_class:=v_rec_class_list(i);

insert into te_number(id,fid,NUM,teskid,STATE,cid,user_code)values(tenumberseq.nextval,v_rec_class.fid,v_rec_class.NUM,v_rec_class.teskid,'-2',v_rec_class.cid,v_rec_class.USERCODE);

end loop;

end inserttenumber;

java

Connection con = null;

CallableStatement cstmt = null;

try {

ApplicationContext  applicationContext=new ClassPathXmlApplicationContext("classpath:spring/applicationContext-resource.xml");

DataSource datasource=(DataSource)applicationContext.getBean("dataSource");

List list = new ArrayList();

for (int i = 0; i < sheets.getRows(); i++) {

Cell c01 = sheets.getCell(1, i);

Cell c00 = sheets.getCell(0, i);

if(!"".equals(c01.getContents())&&!"".equals(c00.getContents())){

total++;

Object[] record = new Object[5];

record[0] = tn.getFid();

record[1] = c01.getContents();

record[2] = tn.getTeskId();

record[3] = tn.getCid();

record[4] = c00.getContents();

list.add(record);

}

if(i%1000==0){

con=(Connection) DataSourceUtils.getConnection(datasource);

System.out.println(con.hashCode()+"======="+list.size());

tnManager.test1(list,con);

list.clear();

System.out.println(con.isClosed());

}

}

System.out.println("============"+list.size());

con=(Connection) DataSourceUtils.getConnection(datasource);

tnManager.test1(list,con);

con.close();

tt.setCount(total);

md.addObject("total",total);

md.addObject("error",tf.getCount()-total);

} catch (Exception e) {

System.out.println("=============新增任务,导入号码文件错误!!!");

e.printStackTrace();

}

closeExcel(rwb);

===================

public void test1(List list,Connection con) throws Exception{

StructDescriptor recDesc = StructDescriptor.createDescriptor("TEST", con);

ArrayList pstruct = new ArrayList();

System.out.println(new Date());

for (int i = 0;i

Object[] record = (Object[])list.get(i);

STRUCT item = new STRUCT(recDesc, con, record);

pstruct.add(item);

}

ArrayDescriptor tabDesc = ArrayDescriptor.createDescriptor("TEST_LIST", con);

ARRAY vArray = new ARRAY(tabDesc, con, pstruct.toArray());

System.out.println(new Date());

CallableStatement cstmt = null;

cstmt = (CallableStatement) con.prepareCall("{call inserttenumber(?)}");

System.out.println(new Date());

cstmt.setArray(1, vArray);

System.out.println(new Date());

cstmt.execute();

System.out.println(new Date());

con.commit();

cstmt.close();

con.close();

System.out.println(new Date()+"==========执行完成"+con.isClosed());

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值