转换sql文件的create table语句为drop table语句
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语句的更多相关文章
- oracle delete t1;drop table t1;drop table t1 purge
Truncate tableTruncate table t1;Ddl语言,自动提交:不能回退:回收范围::挪动高水位线:将所有的数据清除,保留表结构:将表缩的最小:保留表的约束和权限. Drop t ...
- 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 ...
- atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js
atitit.跨语言实现备份mysql数据库 为sql文件特性 api 兼容性java c#.net php js 1. 两个方法:: bat vs mysqldump(推荐) vs lang ...
- 批量执行SQL文件
原文:批量执行SQL文件 摘要:很多时候我们在做系统升级时需要将大量的.sql文件挨个执行,十分不方便.而且考虑到执行顺序和客服的操作方便性,能不能找到一种简单的方法来批量执行这些sql文件呢? 主要 ...
- 利用osql/ocmd批处理批量执行sql文件
原文:利用osql/ocmd批处理批量执行sql文件 上周在测试环境建了几十张表,保存了.sql文件,准备在正式环境重建的时候懒得一个个打开建了,做一在网上搜寻了一下,果然有简单点的方法. 利用osq ...
- Oracle10g 回收站及彻底删除table : drop table xx purge
drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 1.通过查询回收站user_recyclebin获取被删除的表信息, ...
- oracle drop table and purge
一.drop表 执行drop table xx 语句 drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉.这样,回收站里的表信息就可以被恢复,或彻底清除. 通过查询回收站 ...
- 利用硬链接和truncate降低drop table对线上环境的影响
众所周知drop table会严重的消耗服务器IO性能,如果被drop的table容量较大,甚至会影响到线上的正常. 首先,我们看一下为什么drop容量大的table会影响线上服务 直接执行drop ...
- MySQL DROP TABLE操作以及 DROP 大表时的注意事项【转】
删表 DROP TABLE Syntax DROP [TEMPORARY] TABLE [IF EXISTS] tbl_name [, tbl_name] ... [RESTRICT | CASCAD ...
随机推荐
- Centos中彻底删除Mysql(rpm、yum安装的情况)
[root@data lib]# rpm -qa¦grep mysqlmysql-5.5.25-1.el6.remi.i686mysql-libs-5.5.25-1.el6.remi.i686comp ...
- linux-网络使用
linux网络的基本使用 "ifconfig" 查看已经被激活的网卡详细信息 "ifconfig eth0" 查看特定的网卡信息 [root@ssgao ~]# ...
- hadoop kafka install (6)
reference: http://kafka.apache.org/quickstart http://dblab.xmu.edu.cn/blog/1096-2/ hadoop@iZuf68496 ...
- json批量设置DIV属性
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- 快速切题 sgu 111.Very simple problem 大数 开平方 难度:0 非java:1
111.Very simple problem time limit per test: 0.5 sec. memory limit per test: 4096 KB You are given n ...
- DiskGenius注册算法简析
初次接触DiskGenius已经成为遥远的记忆,那个时候还只有DOS版本.后来到Windows版,用它来处理过几个找回丢失分区的案例,方便实用.到现在它的功能越来越强大,成为喜好启动技术和桌面支持人员 ...
- C#foreach的用法
static void Main(string[] args) { int[] a = new int[5] { 1, 2, 3, 4, 5 }; ...
- tensorflow训练打游戏ai
python3,所需模块请自行补齐 # coding=utf8 import pygame import random from pygame.locals import * import numpy ...
- 步步入佳境---UI入门(2)
一,刚开始练习UI的时候,一般是在- (void)viewDidLoad方法中写代码测试,例如:- (void)viewDidLoad{ CGRect rect=CGRectMake(0, 0, ...
- C#反射 字符串转为实体类,并做为参数传入泛型方法中使用
工作中有这样一个需求,有N张不同的报表,每张报表对应一个数据源,统计数据采用内存方式,首先在内在里定义了数据源对应实体.统计条件用lamdba表达式式实现,通过工具对单元格进行定义.在实现过程中针对每 ...