package energy; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.LinkedList; import java.util.List; public class EnergyPo{ String startDate; long totalCount; long totalEnergy; int type; public static void main(String[] args){ //sql 语句,只有一个条件,select * from table where table.startTime between '2009-01-01' and '2009-02-02' order by table.startTime desc String sql = ""; Statement st = null; try { ResultSet rs =st.executeQuery(sql); List<EnergyPo> workList = new LinkedList<EnergyPo>(); List<EnergyPo> weekList = new LinkedList<EnergyPo>(); int workDay = 0; int weekDay =0; EnergyPo workPo = new EnergyPo(); EnergyPo weekPo = new EnergyPo(); while (rs.next()){ if (workDay==5){ workList.add(workPo); workPo = new EnergyPo(); workDay = 0; }else{ //把所有值相加 workPo.totalCount =workPo.totalCount+rs.getLong(1); } if (weekDay==7){ weekList.add(weekPo); weekPo = new EnergyPo(); weekDay = 0; }else{ //把所有值相加 weekPo.totalCount =weekPo.totalCount+rs.getLong(1); } workDay++; weekDay++; } } catch (SQLException e) { e.printStackTrace(); } } }