import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Tables {
private static String driverName = "com.mysql.jdbc.Driver";

public static void main(String[] args) {
Connection con = null ;
Statement stmt =null;
PreparedStatement pstmt = null ;

try {
Class.forName(driverName);
con = DriverManager.getConnection("jdbc:mysql://192.168.5.148/xxx", "root", "123456");
String sql = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'ifms' AND TABLE_TYPE ='BASE TABLE'";
stmt = con.createStatement();
pstmt = con.prepareStatement(sql);
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
String tableName = res.getString(1);
/*stmt = con.createStatement();*/
if(tableName.contains("`")) continue;
ResultSet rs = pstmt.executeQuery("show create table `"+tableName+"`");
while(rs.next()){
File file = new File("C:\\b_tables\\"+tableName+".sql");
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(new FileOutputStream(file));
osw.write(rs.getString(2));
System.out.println(tableName+"导出成功");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
osw.flush();
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.exit(1);
} catch (SQLException e) {
e.printStackTrace();
}finally{
if(pstmt!=null){
try {
pstmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(stmt!=null){
try {
stmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(con!=null){
try {
con.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}

mysql 批量导出建表语句 (视图,函数同理)的更多相关文章

  1. mysql和oracle建表语句以及数据类型的区别

    1.mysql和oracle建表语句的区别 mysql DROP TABLE IF EXISTS `order`;CREATE TABLE `order` (  `id` int(11) NOT NU ...

  2. postgresql 导出建表语句的方法-类似describe table

    https://www.youtube.com/watch?v=PMfcsYzj-9M  这个视频不错, The Definitive Guide to Object-Oriented JavaScr ...

  3. Python导出MySQL数据库中表的建表语句到文件

    为了做数据对象的版本控制,需要将MySQL数据库中的表结构导出成文件进行版本化管理,试写了一下,可以完整导出数据库中的表结构信息 # -*- coding: utf-8 -*- import os i ...

  4. mysql workbench 导出建表语句

    导出建表语句和数据 server—–>data export—–>选中表  注意,export to dump project folder,这种方式是每个表对应一个sql文件.  导出建 ...

  5. MySQL 查询 存储过程 视图 触发器 函数 索引 建表语句 数据库版本 当前登录用户 当前数据库名称

    MySQL 查询 存储过程 视图 触发器 函数 索引 建表语句 数据库版本 当前登录用户 当前数据库名称   INFORMATION_SCHEMA.TABLES INFORMATION_SCHEMA. ...

  6. 三种常用的MySQL建表语句(转)

    MySQL建表语句是最基础的SQL语句之一,下面就为您介绍最常用的三种MySQL建表语句,如果您对MySQL建表语句方面感兴趣的话,不妨一看. 1.最简单的: CREATE TABLE t1(    ...

  7. MySQL建表语句生成Golang代码

    1. 背景 对于后台开发新的需求时,一般会先进行各种表的设计,写各个表的建表语句 然后根据建立的表,写对应的model代码.基础的增删改查代码(基础的增删改查服务可以划入DAO(Data Access ...

  8. sqlserver 建表语句,获取建表语句的存储过程,包括排序规则,索引,字段说明,支持同时生成多个表

    先创建一个分割表名的分割函数 --表值函数用以截取字符串 --如果为其添加一列主键id,则其顺序就会固定了 create FUNCTION [Split](@text NVARCHAR(max)) ) ...

  9. ORACLE 建表语句(表名及字段名大写)

    ORACLE建表时如果表名或者字段名存在大小写同时存在的情况下,默认为区分大小写,此时在select/updata等操作时需要在表名或者字段名上添加双引号,否则会报"视图不存在"的 ...

随机推荐

  1. openfire使用自定义用户表

    转自:http://blog.csdn.net/nomousewch/article/details/7546083 在最近的项目中使用openfire服务器实现消息推送功能,如果使用openfire ...

  2. 初识The Battle of Polytopia

    1.首先了解了一下<文明5-美丽新文明>视频介绍网址:http://list.youku.com/albumlist/show?id=19481409&ascending=1&am ...

  3. LeetCode Find the Celebrity

    原题链接在这里:https://leetcode.com/problems/find-the-celebrity/ 题目: Suppose you are at a party with n peop ...

  4. phpstudy的apache端口没有被占用,也有vc9,防火墙也没开,也开杀毒软件,就是无法启动apache

    我电脑装了一个独立的apche和一个phpstudy的apache,我学习是教学视频是php5.2而phpstudy刚好支持. 但是我在选取phpstudy的php版本5.3n以上就无法启动apach ...

  5. Smokeping安装教程

    Smokeping安装教程 #Smokeping2.6.8安装教程 #2016.3.6 改编v1.0 #Linux运维技术交流 347163978   环境 CentOS release 6.4 (F ...

  6. vim - Convert between hex and decimal

    http://vim.wikia.com/wiki/VimTip448 ga g8

  7. https 与http 的坑

    网页报这种错误: (blocked:mixed-content) 使用了https就不能夹生http       jquery.min.js:4Mixed Content: The page at ' ...

  8. opencv,图片遍历

    //肤色提取,skinArea为二值化肤色图像 void skinExtract(const Mat &frame, Mat &skinArea) { Mat YCbCr; vecto ...

  9. 002-添加网站ico图标

    <link rel="shortcut icon" type="image/x-icon" href="favicon.ico" me ...

  10. Linux下gcc与gdb简介

    gcc编译器可以将C.C++等语言源程序.汇编程序编译.链接成可执行程序.gdb是 GNU 开发的一个Unix/Linux下强大的程序调试工具. linux下没有后缀名的概念.但 gcc 根据文件的后 ...