Execute multiple queries using a single JDBC Statement object

前端 未结 5 2061
说谎
说谎 2021-01-31 17:41

In JDBC, can I use single Statement object to call executeQuery(\"\") multiple times? Is it safe? Or should I close the statement object after each que

5条回答
  •  失恋的感觉
    2021-01-31 18:04

    Yes you can re-use a Statement(specifically a PreparedStatement) and should do so in general with JDBC. It would be inefficient & bad style if you didn't re-use your statement and immediately created another identical Statement object. As far as closing it, it would be appropriate to close it in a finally block, just as you are in this snippet.

    For an example of what you're asking check out this link: jOOq Docs

提交回复
热议问题