zoukankan      html  css  js  c++  java
  • java 后台,根据年份执行一次任务,数据库+1,次年清零

    搞个事件编号 , 规则是: 年份+4位办理次数

        public static String code(String sYear) {
            
            String itemId = "00000000";//事件记录主键
            String sql = "select * from 记录表 where itemid = ? ";
            Object[] objects = { itemId };
            RecordSet rs = SQL.execute(sql, objects);
            String year ="";
            String code ="";
            Integer in = null;
            while(rs.next()){
                year = rs.getString("YEAR");
                in = Integer.parseInt(rs.getString("CODE"));
            }
            if(year.equals(sYear)){//sYear是传入的本年年份
                ++in;
                code = in.toString();
                if(code.length()==1){
                    code = "000"+code;
                }else if(code.length()==2){
                    code = "00"+code;
                }else if(code.length()==3){
                    code = "0"+code;
                }
                 Object[] obj = {sYear,code,itemId};
                 String sq = "update  记录表 set YEAR= ?, CODE= ? where itemid = ? ";
                 RecordSet r = SQL.execute(sq, obj);
                return code;
            }else{
                 code="0001";
                 Object[] obj = {sYear,code,itemId};
                 String sq = "update  数据表 set YEAR= ?, CODE= ? where itemid = ? ";
                 RecordSet r = SQL.execute(sq, obj);
                return sYear+code;
            }
        }

    有大神帮帮看有好点的办法吗?

  • 相关阅读:
    hdu 1195 Open the Lock
    hdu 1180 诡异的楼梯
    hdu 1175 连连看
    背包(采药)
    LCS模板,求长度,并记录子串
    hdu 1159 Common Subsequence
    hdu 1231 最大连续子序列
    DP的简单应用
    hdu 1728 逃离迷宫
    点击页面其他地方,关闭弹框
  • 原文地址:https://www.cnblogs.com/lifan12589/p/12691990.html
Copyright © 2011-2022 走看看