当初工作的时候,需要大量的手机号,移动、联通、电信的都有,应该是整个省的电话号了,只要旅游漫游到一个地方,就发当地的特色信息,应该是这么个业务。当时的问题就是怎么处理好这些电话号,1个小时更新一次,数据量绝对刺激。每次处理10个文件,每个文件20mb左右,录入都是个问题。最后我采用了这个办法解决了问题。
通过当时的工作让我明白的问题就好交给数据库去做。
create or replace type v_varchar is table of nvarchar2(15); create or replace procedure inssell( v_charging in v_varchar, v_address_local in v_varchar, v_address_remote in v_varchar) as i integer; begin for i in 1..v_charging.count loop insert into dx_mms_areainfo (id,charging,address_local,address_remote) values(seq_mms_areainfo.nextval,v_charging(i),v_address_local(i),v_address_remote(i)); end loop; delete from dx_mms_areainfo m where m.rowid > (select min(t.rowid) from dx_mms_areainfo t where m.charging=t.charging); end inssell;
以上是数据库的存储过程,很简单,循环插入数据到一个临时表中,然后和用户表比较,看看用户现在的状态,是不是已经回来本地了。然后删除临时表中的数据。(时间久远记不住了)
然后java代码
public void insertintoareainfo(list list) throws instantiationexception, illegalaccessexception, classnotfoundexception, sqlexception{ getconn getconn = new getconn(); connection con = getconn.getconn(); oracle.sql.arraydescriptor a_id = null; oracle.sql.arraydescriptor a_ticketid = null; oracle.sql.arraydescriptor a_name = null; oracle.sql.arraydescriptor a_age = null; object[] s_id = new object[list.size()]; object[] s_ticketid = new object[list.size()]; object[] s_name = new object[list.size()]; for (int i = 0; i < list.size(); i++) { numberaddress num = (numberaddress) list.get(i); s_id[i] = new string(num.getnumphone()); s_ticketid[i]=new string(num.getnumbelong()); s_name[i]=new string(num.getnumroam()); } try { oracle.sql.arraydescriptor a_nvarchar =arraydescriptor.createdescriptor("v_varchar", con);//一定要大写 array id_test = new array(a_nvarchar, con, s_id); array ticketid_test = new array(a_nvarchar, con, s_ticketid); array name_test = new array(a_nvarchar, con, s_name); callablestatement cstmt = con.preparecall("{call inssell(?,?,?)}"); cstmt.setarray(1, id_test); cstmt.setarray(2, ticketid_test); cstmt.setarray(3, name_test); cstmt.execute(); con.commit(); } catch (exception e) { e.printstacktrace(); system.out.println("insert into db error: " + e.getmessage()); } }