删除90天以前的表

import org.apache.commons.dbutils.BasicRowProcessor;
import org.apache.commons.dbutils.BeanProcessor;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.RowProcessor;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.sql.*; 


public boolean deleteTable() {
        boolean res = false;
        Connection conn = ConnectionUtil.getGpsConnection();
        try {
             Statement stmt = conn.createStatement();
             String sql = "SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' )  FROM information_schema.tables Where table_name LIKE 'gps_veh_package_%' and Length(table_name)=30 and DATEDIFF(now(),str_to_date(substring(table_name, 17, 8),'%Y%m%d'))>90";//substring从1开始数
             ResultSet rs =stmt.executeQuery(sql);
             String sqlConcat="";
             while (rs.next()) { 
                 sqlConcat += rs.getString(1);
             } 
             queryRunner.update(conn, sqlConcat);
            res = true;
        } catch (Exception e) {
            logger.error("创建表存在出现异常:", e);
        } finally {
            ConnectionUtil.closeConnection(conn);
        }
        return res;
    }
原文地址:https://www.cnblogs.com/tonggc1668/p/6434466.html