oracle数据导入导出FTP

  • S2_595136
    了解作者
  • 419.6KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-14 01:12
    上传日期
高性能的oracle文本处理器。java源码放出。sqlload
HB_dosp_3G_product.zip
  • HB_dosp_3G_product
  • DBconfig.class
    2.6KB
  • Test.class
    642B
  • log4j.jar
    344.4KB
  • log
  • file.log
    344B
  • JkConfig.java
    3.5KB
  • FtpOperation.class
    5.5KB
  • DBconfig.java
    2.3KB
  • properties
  • log.properties
    838B
  • HB_dosp_3G_product.properties
    2.9KB
  • FtpOperation.java
    4.4KB
  • sqlloader
  • demo1.ctl
    229B
  • 20130122.log
    1.9KB
  • db_bak
  • 20130122.rar
    879B
  • yasuo.bat
    153B
  • TimePrint.java
    5.7KB
  • load
  • JkConfig.class
    3.3KB
  • .project
    394B
  • commons-net-ftp-2.0.jar
    89KB
  • FtpJkImpl.java
    11.2KB
  • .classpath
    336B
  • start.bat
    279B
  • Test.java
    196B
  • TimePrint.class
    6.6KB
  • FtpJkImpl.class
    10.4KB
内容介绍
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class FtpJkImpl { static Logger logger = Logger.getLogger(Test.class.getName()); private Process proc; private String source_path; private String backup_path; private String rarPath = "C:\\Program Files\\WinRAR\\"; private String deal_path; private String xztime; private String ystime; private FtpOperation ftp = null; private List<String> list; private String end; private String path; private PrintWriter pw; private int number; private String sqlldr_url; public FtpJkImpl() { PropertyConfigurator.configure("./properties/log.properties"); try { // 获取配置文件信息 list = new ArrayList<String>(); source_path = JkConfig.getSource_path(); backup_path = JkConfig.getBackup_path(); deal_path = JkConfig.getDeal_path(); number = JkConfig.getNumber(); FtpOperation.ip = JkConfig.getFtp_ip(); FtpOperation.port = JkConfig.getFtp_port(); FtpOperation.username = JkConfig.getFtp_username(); FtpOperation.password = JkConfig.getFtp_password(); FtpOperation.path = JkConfig.getFtpfile(); path = JkConfig.getPath(); sqlldr_url = JkConfig.getSqlldr_url(); end = JkConfig.getEnd(); run(); } catch (IOException e) { e.printStackTrace(); logger.info(e); } } // 下载条件 时间,路径,名称,后缀 private void run() { ftp = new FtpOperation(); try { // logger.info("连接数据库"); // 获取时间yyyymmdd用于做文件名称 xztime = new TimePrint().yyyymmdd(0);// 昨天日期 ystime = new TimePrint().yyyymmdd(2); FileInputStream inputStream = new FileInputStream( "./properties/HB_dosp_3G_product.properties"); Properties pr = new Properties(); pr.load(inputStream); for (int j = 1; j <= number; j++) { list.add(pr.getProperty("name" + String.valueOf(j))); } // System.out.println(xztime); logger.info("下载文件"); ftp.load(xztime, source_path, list, end); logger.info("数据下载完毕,开始入库!"); deal(); logger.info("入库完毕开始压缩数据!"); yasuo(); logger.info("数据压缩完毕!"); } catch (Exception e) { e.printStackTrace(); logger.info("异常信息: " + e); } } private void deal() { FileInputStream inputStream; File[] file = (new File(source_path)).listFiles(); String tablename = ""; String filename = ""; boolean bl = false; while (file != null && file.length > 0) { for (int k = 0; k < number; k++) { tablename = ""; String[] tool = null; Arrays.sort(file); filename = list.get(k); try { inputStream = new FileInputStream( "./properties/HB_dosp_3G_product.properties"); Properties pr = new Properties(); pr.load(inputStream); tool = pr.getProperty(filename).split(","); if (tool.length == 2) { tablename = tool[0]; // System.out.println(tool[1] ); if (tool[1].equals("1")) { bl = true; } else { bl = false; } } else { if (!(tool[0].equals("00"))) { tablename = tablename + tool[0]; } tablename = tablename + file[0].getName().substring(4, 10); if (!(tool[2].equals("00"))) { tablename = tablename + tool[2]; } if (tool[3].equals("1")) { bl = true; } else { bl = false; } } // System.out.println("111111111" + filename); for (int i = 0; i < file.length; i++) { // System.out.println(file.length); createFile(deal_path + "demo1.ctl"); pw.println("LOAD DATA"); // System.out.println("-----------" + // file[i].getName()); // System.out.println(file[i].getName().indexOf(xztime)); // System.out.println(tablename); if (file[i].getName().indexOf(filename) >= 0 && file[i].getName().length() > 1 && file[i].getName().indexOf(xztime) > 0) { pw.println("INFILE \"" + file[i] + "\""); if (bl) { pw.println("truncate INTO TABLE " + tablename); } else { pw.println("append INTO TABLE " + tablename); } pw .println("fields terminated by '|' OPTIONALLY ENCLOSED BY '\"'");// 分隔符^,OPTIONALLY // ENCLOSED // BY // '\"'去""号 pw.println("trailing nullcols "); pw.write("("); pw.write((pr.getProperty("field" + filename))); // for (int j = 1; j <= 10; j++) { // pw.write((pr.getProperty("field" + // filename+j)) ); // } //System.out.println((pr.getProperty("field"+ filename))); pw.write(")"); pw.flush(); pw.close(); proc = Runtime .getRuntime() .exec( "cmd /c sqlldr userid=" + sqlldr_url + " control=" + deal_path + "demo1.ctl direct=true bindsize=20000000 readsize=20000000 streamsize=20000000 " + "columnarrayrows=30000 date_cache=3000 silent=(header,feedback,errors,discards,partitions) " + "log=" + deal_path + xztime + ".log bad=" + deal_path + xztime + "bad.txt errors=200000"); // proc = // Runtime.getRuntime().exec("cmd /c sqlldr userid="+sqlldr_url+" control=" // +deal_path // + "demo1.ctl log=" +deal_path+list.get(k) + // ".log bad="+deal_path+list.get(k)+"bad.txt errors=200000"); BufferedReader reader = new BufferedReader( new InputStreamReader(proc.getInputStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line).append("\r\n"); } proc.waitFor(); // proc.destroy(); //logger.info("开始备份文件"); // 把文件保存到备份目录 // moveFile(file[0].getName().substring(0,10)); moveFile(file[i].getName()); // Thread.sleep(10000); Arrays.sort(file); } } file = new File(source_path).listFiles(); } catch (Exception e) { e.printStackTrace(); } } //logger.info("程序结束!"); } } // 把文件保存到备份目录 public void moveFile(String filename) { //System.out.println("22222222" + filename); File[] ff = new File(source_path).listFiles(); if (ff != null && ff.length > 0) { for (int i = 0; i < ff.length; i++) { if (ff[i].getName().equals(filename)) { File newfile = new File(backup_path + ff[i].getName()); if (newfile.exists()) { newfile.delete(); } ff[i].renameTo(newfile); } } } } // 压缩文件 private void yasuo() { File[] file = new File(backup_path).listFiles(); File ysfile = new File(backup_path + xztime + ".rar"); if (!ysfile.exists() && file != null && file.length > 0) { File yasuo = new File(backup_path + "yasuo.bat"); if (yasuo.exists()) { yasuo.delete(); } try { yasuo.createNewFile(); } catch (IOException e) { e.printStackTrace(); } try { StringBuffer unrarCmd = new StringBuffer("\"" + rarPath + "rar\" a -ibck -ep1 -df " + backup_path + xztime + ".rar" + " " + "*" + xztime + "*"); BufferedWriter bf = new BufferedWriter(new FileWriter(yasuo)); bf.write(path); bf.newLine(); bf.write("cd " + "../.."); bf.newLine(); bf.write("cd " + backup_path); bf.newLine(); bf.write(unrarCmd.toString()); bf.newLine();
评论
    相关推荐