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
本站主要用于日常笔记的记录和生活日志。本站不保证所有内容信息可靠!(大多数文章属于搬运!)如有版权问题,请联系我立即删除:“abcdsjx@126.com”。
QQ: 1164453243
邮箱: abcdsjx@126.com