How to increment a database field in Spring MVC based on a time period
<p>I have two fields in a database table - <code>date</code> and <code>student number</code>. I want to increment the <code>student number</code> every time I insert something into this table.</p>

<p>I would like to take period-based cut-offs for the <code>student number</code> field. The first record to be inserted in a period should get inserted with <code>student number = 1</code>, the second with <code>student number = 2</code>, the third with <code>student number = 3</code> and so on.</p>

<p>For example, each day could be treated as one period. Then, if today is <code>05/02/2016 (May 2, 2016)</code> the first student record to get inserted would get <code>student number = 1</code>. When the date changes to <code>05/03/2016 (May 3, 2016)</code> I want the <code>student number</code> to be reset to 1.</p>

<p>So the database table should look like this:</p>

<pre><code> ---------------------------
| date     | student number |
 ---------------------------
| 05/02/16 | 1              |
| 05/02/16 | 2              |
| 05/02/16 | 3              |
| 05/03/16 | 1              |
 ---------------------------
</code></pre>

<p>This is in my controller code for insertion:</p>

<pre><code>student.setStudentNo(job.getStudentType()
                     .concat("_")
                     .concat(Constants.datetimeJobDF.format(new Date()))
                     .concat("_"));
</code></pre>