请大佬指教,要如何实现Java从数据库接口调取10年数据(一次只能调取24个的月的)

这是原代码,从数据库提取24个月(一次只能提取24个月的)的数据,现在需要提取(2010年-2020年)10年的数据,要怎么用循环实现呢,求大佬指教。

public static void main(String[] args) {
        
        /* 1. 定义client对象 */
    DataQueryClient client = new DataQueryClient() ;
        
        /* 2. 调用方法的参数定义,并赋值 */
        /* 2.1 用户名&密码 */
        String userId = "XXX" ;
        String pwd = "XXX";
        /* 2.2  接口ID */
        String interfaceId = "XXX" ;    
        /* 2.3  接口参数,多个参数间无顺序 */
        HashMap<String, String> params = new HashMap<String, String>();
        //必选参数
        params.put("dataCode", "XXX"); //资料代码,中国地面
        params.put("timeRange", "(20190101000000,20201231000000]"); //统计时间段,时间范围,前开后闭
        //可选参数
        params.put("adminCodes", "530000");
        params.put("elements", "Station_ID_C,Station_Name,City,Cnty,Town,Lat,Lon,Alti,Year,Mon,Day,PRE_Time_2020"); //统计分组要素:站号,站名
          params.put("staLevels", "011,012,013") ; 
            
            params.put("orderBy", "Station_ID_C:desc,Mon:asc,Day:asc"); 
      
        params.put("limitCnt", "100000000") ; //返回最多记录数:
        String dataFormat="html";
        String savePath="F:/temp/test.html";
        
         RetFilesInfo retFilesInfo = new RetFilesInfo() ;
         
        for(long timeRange=20200101000000L;timeRange<20210101010000L;timeRange=timeRange+20000000000L){
            try {
                //初始化接口服务连接资源
                client.initResources() ;
                //调用接口
                int rst = client.callAPI_to_saveAsFile(userId, pwd, interfaceId, params,dataFormat,savePath ,retFilesInfo) ;
                //输出结果
                if(rst == 0) { //正常返回
                     ClibUtil clibUtil = new ClibUtil() ;
                    clibUtil.outputRst( retFilesInfo ) ;
                } else { //异常返回
                    System.out.println( "[error] StaElemStatAPI_CLIB_callAPI_to_array2D." ) ;                
                    System.out.printf( "\treturn code: %d. \n", rst ) ;
                    System.out.printf( "\terror message: %s.\n", retFilesInfo.request.errorMessage ) ;
                }    
            
            
            } catch (Exception e) {
                //异常输出
                e.printStackTrace() ;
            } finally {
                //释放接口服务连接资源
                client.destroyResources() ;
            }
        }
        

    }    
            
        }
        /* 3. 调用接口 */
        
        

难点在哪

public class Test {
    public static void main(String[] args) {
        /* 1. 定义client对象 */
        DataQueryClient client = new DataQueryClient();

        /* 2. 调用方法的参数定义,并赋值 */
        /* 2.1 用户名&密码 */
        String userId = "XXX";
        String pwd = "XXX";

        /* 2.2  接口ID */
        String interfaceId = "XXX";

        /* 2.3  接口参数,多个参数间无顺序 */
        HashMap<String, String> params = new HashMap<String, String>();
        //必选参数
        params.put("dataCode", "XXX"); //资料代码,中国地面
                                       //可选参数

        params.put("adminCodes", "530000");
        params.put("elements",
            "Station_ID_C,Station_Name,City,Cnty,Town,Lat,Lon,Alti,Year,Mon,Day,PRE_Time_2020"); //统计分组要素:站号,站名
        params.put("staLevels", "011,012,013");

        params.put("orderBy", "Station_ID_C:desc,Mon:asc,Day:asc");

        params.put("limitCnt", "100000000"); //返回最多记录数:

        String dataFormat = "html";
        String savePath = "F:/temp/test.html";

        RetFilesInfo retFilesInfo = new RetFilesInfo();

        int leftRangeYear = 2009;
        int rightRangeYear = 2020;

        /*
                (20090101000000,20111231000000]
                (20111231000000,20131231000000]
                (20131231000000,20151231000000]
                (20151231000000,20171231000000]
                (20171231000000,20191231000000]
                (20191231000000,20201231000000]
        */
        for (int i = 0, startYear = leftRangeYear, endYear = leftRangeYear + 2;
                i < 6; i++, endYear += 2, startYear += 2) {
            endYear = Math.min(endYear, rightRangeYear);

            String startParam = startYear +
                ((i == 0) ? "0101000000" : "1231000000");
            String endParam = endYear + "1231000000";
            String timeRange = "(" + startParam + "," + endParam + "]";
            // 每次循环都设置新的时间
            params.put("timeRange", timeRange);

            try {
                //初始化接口服务连接资源
                client.initResources();

                //调用接口,
                int rst = client.callAPI_to_saveAsFile(userId, pwd,
                        interfaceId, params, dataFormat, savePath, retFilesInfo);

                //输出结果
                if (rst == 0) { //正常返回

                    ClibUtil clibUtil = new ClibUtil();
                    clibUtil.outputRst(retFilesInfo);
                } else { //异常返回
                    System.out.println(
                        "[error] StaElemStatAPI_CLIB_callAPI_to_array2D.");
                    System.out.printf("\treturn code: %d. \n", rst);
                    System.out.printf("\terror message: %s.\n",
                        retFilesInfo.request.errorMessage);
                }
            } catch (Exception e) {
                //异常输出
                e.printStackTrace();
            } finally {
                //释放接口服务连接资源
                client.destroyResources();
            }
        }
    }
}

 

1.看你这个用法,你是在调用别人的API,然后把获取到的数据存到文件里?

2.如果是这样的话,对方的API是一次只能获取一年的数据

3.如果可以,用年做限制条件获取,10年就是获取10次了

你好,我是有问必答小助手。为了技术专家团更好地为您解答问题,烦请您补充下(1)问题背景详情,(2)您想解决的具体问题,(3)问题相关图片。便于技术专家团更好地理解问题,并给出解决方案。

您可以点击问题下方的【编辑】,进行补充修改问题。