PreparedStatement caching - what does it mean (how does it work)

后端 未结 2 1846
难免孤独
难免孤独 2021-02-07 10:12

I\'m using for example c3p0 with some defined \"maxStatements\" for preparedStatement caching. What does this caching really do? What kind of data it caches. On what level (db,

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-07 10:52

    Without caching, you will get a new PreparedStatement each time you request one from the Connection. With caching, you will frequently get the exact same Java object of type PreparedStatement if you provide the same SQL string. If you provide the same SQL to a PreparedStatement, even with different parameters, often the database can reuse information like the execution plan, but only if you continue to use the same PreparedStatement. Caching makes that easier by not requiring your app to hold on to that PreparedStatement reference itself.

提交回复
热议问题