用java遍历mysql数据库所有表,并优化

白色玫瑰 程序猿

时间: 2023-07-11 阅读: 1 字数:1931

{}
Connection conn = null; String url = "jdbc:mysql://ip地址:3306/数据库名&user=用户名&password=密码&useUnicode=true&characterEncoding=UTF8"; ...

目录

Connection conn = null;
        String url = "jdbc:mysql://ip地址:3306/数据库名&user=用户名&password=密码&useUnicode=true&characterEncoding=UTF8";
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection(url);
        Statement stmt = conn.createStatement();
        String sql = "SHOW TABLE STATUS FROM `数据库名`;";
        ResultSet rs = stmt.executeQuery(sql);
        HashSet<String> tables=new HashSet<String>();
        while (rs.next()) {
            String tname =rs.getString("Name");
            tables.add(tname);
        }
        rs.close();
        for(String tb:tables){            
            stmt.execute("optimize table "+tb);
        }
        stmt.close();

转载于:https://my.oschina.net/jingshishengxu/blog/3089201

原文地址:https://blog.csdn.net/chulict9704/article/details/100759187?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168904449916800185828444%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=168904449916800185828444&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-14-100759187-null-null.142^v88^control_2,239^v2^insert_chatgpt&utm_term=java%E4%BC%98%E5%8C%96

本文章网址:https://www.sjxi.cn/detil/182504b71f1043e186d1662ff0fb83b2

打赏作者

本站为非盈利网站,如果您喜欢这篇文章,欢迎支持我们继续运营!

最新评论
当前未登陆哦
登陆后才可评论哦

湘ICP备2021009447号

×

(穷逼博主)在线接单

QQ: 1164453243

邮箱: abcdsjx@126.com

前端项目代做
前后端分离
Python 爬虫脚本
Java 后台开发
各种脚本编写
服务器搭建
个人博客搭建
Web 应用开发
Chrome 插件编写
Bug 修复