package com.csii.pweb.query.action;

 import java.io.BufferedReader;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;

 public class JavaFile {
     public static void main(String[] args) {
         try {
             // read file content from file
             StringBuffer sb= new StringBuffer("");

             FileReader reader = new FileReader("D:/t/workflow.sql");
             BufferedReader br = new BufferedReader(reader);

             String str = null;
             final String markStart = "CREATE TABLE";
             List<String> tableNames = new ArrayList<String>();
             while((str = br.readLine()) != null) {
                 str = str.toUpperCase().trim(); //转为大写并去除两端空格
                 if(str.startsWith(markStart) && !str.startsWith("--")) {    //非注释之建表语句
                     str = str.substring(markStart.length()).replace('(', ' ');    //取表名
                     tableNames.add("DROP TABLE " + str.trim()+";");
 //                    System.out.println(str);
                 }
             }

             br.close();
             reader.close();
             //倒序
             for(int i=tableNames.size()-1; i>=0;i--) {
                 String name = tableNames.get(i);
                 sb.append(name).append("\n");
             }
             System.out.println("--------------start---------------");
             System.out.println(sb);
             System.out.println("--------------end---------------"+tableNames.size());

             // write string to file
 //            FileWriter writer = new FileWriter("c://test2.txt");
 //            BufferedWriter bw = new BufferedWriter(writer);
 //            bw.write(sb.toString());
 //
 //            bw.close();
 //            writer.close();
         }
         catch(FileNotFoundException e) {
             e.printStackTrace();
         }
         catch(IOException e) {
             e.printStackTrace();
         }
     }
 }

转换sql文件的create table语句为drop table语句的更多相关文章

  1. oracle delete t1;drop table t1;drop table t1 purge

    Truncate tableTruncate table t1;Ddl语言,自动提交:不能回退:回收范围::挪动高水位线:将所有的数据清除,保留表结构:将表缩的最小:保留表的约束和权限. Drop t ...

  2. Mysql运行SQL文件 错误Incorrect table definition;there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause

    问题描述 想从服务器上DOWN下数据库.操作:先把数据库转存为SQL文件,然后在本地利用navicate运行SQL文件,出现错误信息: Incorrect table definition;there ...

  3. atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js

    atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐)  vs   lang  ...

  4. 批量执行SQL文件

    原文:批量执行SQL文件 摘要:很多时候我们在做系统升级时需要将大量的.sql文件挨个执行,十分不方便.而且考虑到执行顺序和客服的操作方便性,能不能找到一种简单的方法来批量执行这些sql文件呢? 主要 ...

  5. 利用osql/ocmd批处理批量执行sql文件

    原文:利用osql/ocmd批处理批量执行sql文件 上周在测试环境建了几十张表,保存了.sql文件,准备在正式环境重建的时候懒得一个个打开建了,做一在网上搜寻了一下,果然有简单点的方法. 利用osq ...

  6. Oracle10g 回收站及彻底删除table : drop table xx purge

    drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...

  7. oracle drop table and purge

    一.drop表 执行drop table xx 语句 drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 通过查询回收站 ...

  8. 利用硬链接和truncate降低drop table对线上环境的影响

    众所周知drop table会严重的消耗服务器IO性能,如果被drop的table容量较大,甚至会影响到线上的正常. 首先,我们看一下为什么drop容量大的table会影响线上服务 直接执行drop ...

  9. MySQL DROP TABLE操作以及 DROP 大表时的注意事项【转】

    删表 DROP TABLE Syntax DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name] ... [RESTRICT | CASCAD ...

随机推荐

  1. logistic 回归与线性回归的比较

    可以参考如下文章 https://blog.csdn.net/sinat_37965706/article/details/69204397 第一节中说了,logistic 回归和线性回归的区别是:线 ...

  2. linux和window是文件挂载

    1. 首先在windows下面创建share文件夹并设置共享(右键->属性->共享)2. 确认ubuntu安装了mount.cifs,apt-get install mount.cifs ...

  3. learning uboot enable protect console

    reference :https://github.com/lentinj/u-boot/blob/master/doc/README.autoboot how to enable protect s ...

  4. 跟我一起学习ASP.NET 4.5 MVC4.0(五)

    前面几篇文章介绍了一下ASP.NET MVC中的一些基础,今天我们一起来学习一下在ASP.NET MVC中控件的封装.在页面中我们会经常使用到Html对象,来程序控件,当然这里的控件不是说ASP.NE ...

  5. 抓取错误之onerror

    一处定义,可以抓取全局的错误,相当于一个全局的try catch呀. <html> <head> <script type="text/javascript&q ...

  6. [转]TFS.VisualStudio.com TF30063: You are not authorized to access Collection

    If you are trying to connect to team foundation server online through visual studio and you get unau ...

  7. docker中的安全机制

    有时候我们需要容器具有更多的权限,像如操作内核模块,控制swap交换分区,挂载usb磁盘,修改mac地址等.所以我们今天进行docker的安全设定. 一.使用docker命令设置docker的安全机制 ...

  8. bootstrap-treeview 自定义实现双击事件

    bootstrap-treeview是一款效果非常酷的基于bootstrap的jQuery多级列表树插件.该jQuery插件基于Twitter Bootstrap,以简单和优雅的方式来显示一些继承树结 ...

  9. oracle function用法(本文来自百度文库)

    函数调用限制 1.SQL语句中只能调用存储函数(服务器端),而不能调用客户端的函数 2.SQL只能调用带有输入参数,不能带有输出,输入输出函数 3.SQL不能使用PL/SQL的特有数据类型(boole ...

  10. php 易忽略问题