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

后端 未结 2 1844
难免孤独
难免孤独 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:49

    John Watts' answer is very good.

    Note that there is no example code that can be provided because Statement caching is transparent: code that uses it looks exactly like code that does not. You just turn Statement caching on, in c3p0, by setting maxStatements and or maxStatementsPerConnection to a positive value.

    Any performance benefit from statement caching is database/JDBC driver dependent. To see if statement caching helps, try to profile your app first with statement caching off and then with maxStatementsPerConnection set to the number of prepared statement queries that your app uses repeatedly. For some apps/databases/drivers, you'll see a significant benefit. For others you won't see any material benefit.

提交回复
热议问题