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. office每次打开都要重新配置

    office每次打开都要重新配置     1● 找到路径 C:\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Co ...

  2. vue项目启动

    这篇文章主要用于有源码vue项目安装: 1.安装node.js环境(npm包管理器)前面博客有写到如何安装: 2.vue-cli 脚手架构建工具前面博客有写到如何安装: 3.cnpm  npm的淘宝镜 ...

  3. bzoj1677

    题解: 背包 每一个1<<i都是无限量 代码: #include<bits/stdc++.h> using namespace std; ,M=1e9; int n,dp[N] ...

  4. flashfxp 命令行

    以后更新软件时,尽量用bat命令行 http://www.flashfxp.com/forum/flashfxp/frequently-asked-questions-faq-/14748-comma ...

  5. MyEclipse CI 2018.8.0正式发布(附下载)

    MyEclipse线上特惠,在线立享专属折扣!火热开启中>> MyEclipse 2018最终版日前正式发布,新版本通过构建Eclipse Photo.支持Java 10和Java EE ...

  6. MyEclipse移动开发教程:迁移HTML5移动项目到PhoneGap(二)

    MyEclipse开年钜惠 在线购买低至75折!立即开抢>> [MyEclipse最新版下载] 二.将文件从HTML5项目复制到PhoneGap项目中 1. 在HTML5 app项目的ww ...

  7. uri 定义

    function path(){ $path=explode("/",$_SERVER['REQUEST_URI']); unset($path[(count($path)-1)] ...

  8. git stash,git cherry-pick

    git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致.同时,将当前的工作区内容保存到Git栈中.git stash pop: 从Git栈中读取 ...

  9. buy now按钮的添加

    样例是 www.dealfreeship.com:在D:\xampp\htdocs\aliexpress\app\design\frontend\default\se101\template\cata ...

  10. git中的needs merge问题

    这个问题是在先“储藏”起来了,后面再调用出来出现的错误. 解决的方法就是通过git add    ,git commit -m  提交上去就可以了.