Best way to manage database connection for a Java servlet

前端 未结 9 505
南方客
南方客 2020-12-02 10:28

What is the best way to manage a database connection in a Java servlet?

Currently, I simply open a connection in the init() function, and then close it

9条回答
  •  旧时难觅i
    2020-12-02 10:51

    Are you pooling your connections? If not, you probably should to reduce the overhead of opening and closing your connections.

    Once that's out of the way, just keep the connection open for as long as it's need, as John suggested.

提交回复
热议问题