plsql导入一个文件夹下所有excel

时间:2014-05-18 04:55:19   收藏:0   阅读:368
import java.io.File;
import java.util.ArrayList;
import jxl.Sheet;
import jxl.Workbook;
import com.jielan.util.DBUtil;
import com.jielan.util.Oracle;

public class Test {
	
	
	private ArrayList<String> filelist = new ArrayList<String>();
	public static void main(String[] args) {
		DBUtil.startProxool();
		Test t=new Test();
		t.getFiles("C:\\Documents and Settings\\Administrator\\桌面\\wenzhou\\sanyue");
		t.duqu();
	}
	
	
	public void duqu(){
		Bean bean=null;
		try {
			for(int j=0 ;j<filelist.size() ;j++){
				Workbook wbook=Workbook.getWorkbook(new File(filelist.get(j)));
				Sheet sheet=wbook.getSheet(0);
				int i=0;
				for( i=1 ;i<sheet.getRows();i++){//第一行为标题行不导入
					bean=new Bean();//excel的列相对应的bean
					bean.setShoujihao(sheet.getCell(0, i).getContents());
 					bean.setCtime(sheet.getCell(1, i).getContents());
					bean.setCtype(sheet.getCell(2, i).getContents());
 					bean.setMoney(sheet.getCell(3, i).getContents());
					bean.setStatus(sheet.getCell(4, i).getContents());
					//把bean插入oracle
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}

	
	
	private void getFiles(String filePath){
		File dir = new File(filePath); 
        File[] files = dir.listFiles(); 
        
        if (files == null) 
            return; 
        for (int i = 0; i < files.length; i++) { 
            if (files[i].isDirectory()) { 
            	getFiles(files[i].getAbsolutePath()); 
            } else { 
                filelist.add(files[i].getAbsolutePath());                    
            } 
        } 
	}
}


为了解决这个问题所编写的代码

以上方法导百万数据没问题

plsql导入一个文件夹下所有excel,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!