搞个事件编号 , 规则是: 年份+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; } }
有大神帮帮看有好点的办法吗?