数据库表中MAX ID获取,确保每次调用没有重复工具类(NumberUtil)

下面这个类是获取数据库中一个字段的最大值。配置在数据库中。

public class NoFactory { private final static Logger cLogger = Logger.getLogger(NoFactory.class); protected static final byte cClusterId = 0; protected static final byte cClusterCount = 1; private static final byte[] BLCTRANNOId = new byte[0]; private static int BLCTRANNO; static { try { BLCTRANNO = Integer.parseInt(new ExeSQL().getOneValue("select max(to_number(BLCTRANNO)) from edorrenewalbalanceacc where mod(BLCTRANNO,"+cClusterCount+")="+cClusterId)); } catch (Throwable ex) { cLogger.error("初始化最大号异常!", ex); } } public final static int nextBLCTRANNONo() { synchronized (BLCTRANNOId) { BLCTRANNO += cClusterCount; } return BLCTRANNO; } public final static void setBLCTRANNONo(int pMaxNo) { synchronized (BLCTRANNOId) { BLCTRANNO = pMaxNo - pMaxNo%cClusterCount + cClusterId; } } }

  

原文地址:https://www.cnblogs.com/zhangyue086/p/3402835.html