话说今天不知道是抽风了还是失魂了,在用phpmyadmin删除测试数据时,竟然将整个表删除了:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | package com.nerve.sql.reload; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.util.ArrayList; import java.util.List; import org.nerve.util.NumberUtil; /** * @project: cloudOffice_swing * @file: ReloadWorker.java * @package: com.nerve.sql.reload * @description: * 将二进制日志导出的文件中相应表的操作记录提出出来 * @author: 集成显卡 1053214511@qq.com * @date&time: Jan 23, 2014 * @change log: */ public class ReloadWorker { public void read(List<String> orgF, String targetF, String table) throws Exception{ BufferedWriter bw = new BufferedWriter( new FileWriter(targetF, true )); for (String or:orgF){ BufferedReader br = new BufferedReader( new FileReader(or)); String t = null ; String t2 = null ; table = table.toUpperCase(); while ((t=br.readLine())!= null ){ t2 = t.toUpperCase(); /* * 如果是update操作,直接提出 */ if (t2.startsWith( "UPDATE " +table)){ bw.append(t+ ";n" ); } /* * 如果是insert语句,因为有一些旧服务器的数据 * 所以要先执行delete操作 */ else if (t2.startsWith( "INSERT INTO " +table)){ String ids = t2.substring(t2.lastIndexOf( "," )); bw.append( "delete from " +table+ " where id=" +NumberUtil.toDigital(ids)+ ";n" ); bw.append(t+ ";n" ); } /* * sql语句后面都要加 ; ,因为原来没有,不加的话,在导入到数据库时,出错 */ } br.close(); } bw.flush(); bw.close(); } public static void main(String[] args) throws Exception{ long sd = System.currentTimeMillis(); ReloadWorker w = new ReloadWorker(); List<String> orgs = new ArrayList<String>(); orgs.add( "C:/Users/IBM_ADMIN/Desktop/000015.txt" ); orgs.add( "C:/Users/IBM_ADMIN/Desktop/000016.txt" ); orgs.add( "C:/Users/IBM_ADMIN/Desktop/000017.txt" ); orgs.add( "C:/Users/IBM_ADMIN/Desktop/000018.txt" ); orgs.add( "C:/Users/IBM_ADMIN/Desktop/000019.txt" ); String targetS = "C:/Users/IBM_ADMIN/Desktop/000017_sql.txt" ; w.read(orgs, targetS, "task" ); System.out.println( "DONE, on " +(System.currentTimeMillis() - sd)/ 1000 + " s" ); } } |