现在要实现以导入并更新功能,不是使用数据库自带的导入功能,
而是使用编写程序的方式来实现;
具体功能如下:
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(); } }
解决 无用评论 打赏 举报
悬赏问题
- ¥20 测距传感器数据手册i2c
- ¥15 RPA正常跑,cmd输入cookies跑不出来
- ¥15 求帮我调试一下freefem代码
- ¥15 matlab代码解决,怎么运行
- ¥15 R语言Rstudio突然无法启动
- ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
- ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
- ¥15 用windows做服务的同志有吗
- ¥60 求一个简单的网页(标签-安全|关键词-上传)
- ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法