生成日表 // day String sql1 = "create table " + table + // 该表名要用Calendar日期计算得出, 格式:logs_day_20100709 " ("+ " logName varchar(20),"+ " labIP varchar(15),"+ " durations numeric(12),"+ " logMonth date,"+ " constraint logs_day_pk primary key(logName,labIP)"+ ")"; // 汇总查询,其中两个参数为前一天0点毫秒值,今天0点毫秒值 String sql2 = "select logName, labIP, sum(durations) " + " from logs where loginTime>=? and loginTime<? " + " group by logName, labIP"; // 在日表中插入数据 String sql3 = "insert into "+ table +"(logName, labIP, durations, logMonth) " + " values(?,?,?,?)"; 生成月表 String sql1 = "create table "+ monthTable+ // 该表名要通过Calendar日期计算得出, 格式:logs_month_201007 " ("+ " logName varchar(20),"+ " labIP varchar(15),"+ " durations numeric(12),"+ " logMonth date,"+ " constraint logs_day_pk primary key(logName,labIP)"+ ")"; // 创建临时表 String sql2 = "create temporary table temp_month_table"+ " ("+ " logName varchar(20),"+ " labIP varchar(15),"+ " durations numeric(12)"+ ")"; // 在临时表中插入数据 // 要对上个月每一天的日表进行遍历, // 对每张日表执行该语句 // String sql3 = "insert into temp_month_table(logName,labIP,durations) " + " select logName, labIP, durations from "; //// // 将临时表数据汇总批量插入月表 String sql4 = "insert into "+monthTable+"(logName,labIP,durations,logMonth) " + " select logName,labIP,sum(durations),'"+month+"' " + " from temp_month_table group by logName, labIP";