It depends on your code.....
But one thing seems very obvious..
you might have done something like you intialized the variable , started incrementing that and putting in database.So, the problem is when the
Servlet reloads that variable might be again setted to its intial value.
I assumed this problem depending upon your Query.