When using java+mysql I came up with two methods to traverse through the datasets
You should avoid the best you can stored procedures as they are much more complex to maintain than a Java application and they are specific to the target database. You should only use stored procedures for complex use cases that cannot be managed with queries executed thanks to a
In other words
99.9 % of the time, your best choice will be #2.