We don't just remove threads because they are solved. Others may learn from our mistakes. Which is why I would like you to share your solution with us, please.
Also, you have some code duplication there, with adding the longs. Perhaps you'd like to make methods out of those:
Indeed so, I missed that. As a result, only the rs.getLong("a") statement is inside the loop. All others are executed after the loop has ended and you've already gone through all records.