public voidaddAll(String url){//生成一个备用码
String guid=RandomUtils.myGetNo(9);//将excel数据转为集合并以100条每次的节奏插入临时表中
Workbook rwb = null;try{//InputStream is = new FileInputStream("F:/龙里县贫困户.xls");
InputStream is = newFileInputStream(url);
rwb=Workbook.getWorkbook(is);
}catch(Exception ex) {
ex.printStackTrace();
}//获取第一张Sheet表
Sheet rs = (Sheet) rwb.getSheet(0);//总行数
int rsRows =rs.getRows();//总列数
int rsColumns =rs.getColumns();
Cell c1,c2= null;
String strTmp1,strTmp2="";int no=Integer.parseInt(findMaxId())+10;
System.out.println("总行数"+rsRows+"总列数"+rsColumns+" "+no);try{
openConn();//设置为不自动提交,等凑足100条的时候再批量提交一次
conn.setAutoCommit(false);
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
}catch(SQLException e1) {
e1.printStackTrace();
}for(int i=2;i
c1= ((jxl.Sheet) rs).getCell(0, i);
strTmp1=c1.getContents();
c2= ((jxl.Sheet) rs).getCell(1, i);
strTmp2=c2.getContents();
no++;if(!strTmp1.equals("") && !strTmp3.equals("")){
StringBuilder strSql= newStringBuilder();
strSql.append(" INSERT INTO CUST_OBJECT_TEMP ");//CUST_OBJECT_TEMP
strSql.append(" (CUST_ID,CREDENTIALS,COUNZHENG,GUID) ");
strSql.append(" VALUES ");
strSql.append(" ('"+no+"','"+strTmp1+"','"+strTmp2+"','"+guid+"') ");try{
stmt.execute(strSql.toString());//100条数据提交一次
if(i%100==0||i==(rsRows-1)){
conn.commit();
}
}catch(SQLException e) {
e.printStackTrace();
}
}
}try{
closeAll();
}catch(Exception e) {
e.printStackTrace();
}//至此所有的excel数据都已经插入到了临时表CUST_OBEJCT_YEMP中了//注意:临时表除了有正是表的所有字段,还额外新增了两个字段
1、IF_INSERT 建表的时候默认为0 表示该数据还没有插入正式表 ,当插入正是表之后,会变为1.2、GUID 标识了数据的批次,String guid=RandomUtils.myGetNo(9); 每一次excel导入的数据都同属于一个批次。//调用存储过程
excelAlladd(guid);
}