Punith R Kashi Punith R Kashi - 1 year ago 101
SQL Question

Difference between resultset in java and cursor in mysql

When using java+mysql I came up with two methods to traverse through the datasets

  1. Using cursor and stored procedure in sql and then execute it in java to find whether the user exist or not.

  2. Using "resultSet" in java to find the user exist or not.

Can anyone tell me which is efficient to use and why?

Answer Source

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 Statement/PreparedStatement.

In other words 99.9 % of the time, your best choice will be #2.