mysql 如果存在id則設資料自增加1 ,不存在則添加。java月份計算比較,mysql.java
</pre><pre name="code" class="sql">INSERT INTO invite_rejectlog_num (player_id,MONTH,count,last_modify_time)VALUES (#{playerId},#{month},#{count},#{lastModifyTime})ON DUPLICATE KEY UPDATE count=count+1;
需要唯一約束 id和月份
ava月份計算比較
Calendar calDelM = Calendar.getInstance();calDelM.set(Calendar.MONTH, 0);System.out.println(calDelM.get(Calendar.MONTH));calDelM.add(Calendar.MONTH, -1);System.out.println(calDelM.get(Calendar.MONTH));// ix 遍曆需要刪除的月份int isdel = calDelM.get(Calendar.MONTH);int ix = 8;// 緩衝最小月份Calendar calDelM2 = Calendar.getInstance();calDelM2.set(Calendar.MONTH, ix);ix = calDelM2.get(Calendar.MONTH);// ix<isdelCalendar calDelM3 = Calendar.getInstance();calDelM3.set(Calendar.MONTH, calDelM.get(Calendar.MONTH));for (; calDelM2.compareTo(calDelM3) != -1;) {System.out.println("================");System.out.println("calDelM2:" + calDelM2.get(Calendar.MONTH) + " "+ " calDelM:" + calDelM.get(Calendar.MONTH)+ " calDelM3: " + calDelM3.get(Calendar.MONTH));System.out.println(calDelM2.compareTo(calDelM3));calDelM.add(Calendar.MONTH, -1);isdel = calDelM.get(Calendar.MONTH);calDelM3.set(Calendar.MONTH, calDelM.get(Calendar.MONTH));System.out.println("del:" + isdel);System.out.println("================");}