• 删除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;
        }
  • 相关阅读:
    00. 以太坊私有链创世区块
    01. 以太坊部署智能合约
    IDEA 调试技巧
    CI/CD 容器服务准备
    Redis 存储机制及淘汰策略
    02. 最佳实践
    Spring 事务
    百度图片式的瀑布流
    线程
    Vue3+TS如何判断对象类型数组中包含某一个值
  • 原文地址:https://www.cnblogs.com/tonggc1668/p/6434466.html
Copyright © 2020-2023  润新知