现在要实现以导入并更新功能,不是使用数据库自带的导入功能,
而是使用编写程序的方式来实现;
具体功能如下:
1、 首先要判断该目录有没有此文件(*.CSV)
2、然后要读取里面的数据,(csv文件里的格式是以","分隔的)
我需要对其进行分组;(好和数据库里的字段想对应)
csv文件格式的第一列是和数据库的某个字段是相对应的(就是更新条件)
csv格式是"文本,值","文本,值"。。。。
哪位大神给力啊!急需
非常感谢
如何将某个文件(如:*.csv)导入oracle数据库并更新
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- qinmeng82722 2015-05-18 02:45关注
if(null!=filename){
long before = System.currentTimeMillis(); long after =0; //根据附件上传的ID得到附件的路径 String excellink=proDuctService.getfjmc(filename); String newpath="d:/jboss-4.2.2.GA/server/default/tmp/deploy/data.csv"; //把取出来的文件复制到另一个目录下,并保存成csv文件 try { int bytesum = 0; int byteread = 0; File oldfile = new File(excellink); if (oldfile.exists()){ //文件存在时 InputStream inStream = new FileInputStream(excellink); //读入原文件 FileOutputStream fs = new FileOutputStream(newpath); byte[] buffer = new byte[2000]; while ( (byteread = inStream.read(buffer)) != -1) { bytesum += byteread; //字节数 文件大小 fs.write(buffer, 0, byteread); } inStream.close(); } } catch (Exception e) { e.printStackTrace(); } File files=new File("d:/data.ctl"); if(!files.exists()){ files.createNewFile(); } FileWriter fw=new FileWriter("d:/data.ctl",false); BufferedWriter bw=new BufferedWriter(fw); bw.write("load data\r\ninfile '"+newpath+"'\r\nappend into table "+tablename+"\r\nfields terminated by ','\r\n("+col+")"); fw.flush(); bw.close(); fw.close(); String sql = "sqlldr userid="+dlname+"/"+passname+"@"+dataname+" control='d:/data.ctl' log='d:/jboss-4.2.2.GA/server/default/deploy/goa.ear/goa.war/datalog/"+filename+".log'"; try { Runtime.getRuntime().exec(sql.toString()); } catch (IOException e) { e.printStackTrace(); }finally{ after = System.currentTimeMillis(); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
- ¥15 python的qt5界面
- ¥15 无线电能传输系统MATLAB仿真问题
- ¥50 如何用脚本实现输入法的热键设置
- ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
- ¥30 深度学习,前后端连接
- ¥15 孟德尔随机化结果不一致
- ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
- ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
- ¥15 谁有desed数据集呀