Is it Ok to Pass ResultSet?

后端 未结 2 1311
栀梦
栀梦 2020-12-10 14:44

In my situation, I am querying a database for a specific return (in this case registration information based on a username).

            //Build SQL String a         


        
2条回答
  •  轮回少年
    2020-12-10 15:17

    Technically, it's OK to pass result sets, as long as you are not serializing and passing it to a different JVM, and your JDBC connection and statement are still open.

    However, it's probably a better software engineer and programming practice to have DB access layer that returns you the result set in a Java encoded way (a list of User in your example). That way, your code would be cleaner and you won't have to worry if the ResultSet is already opened, or you have to scroll it to the top, you name it...

提交回复
热议问题