2

Can anyone explain in clear terms what the difference between implicit and explicit statement caching is in Oracle (as described here).

I basically want to reproduce the functionality that the DBCP connection pool gave, such that a statement is only sent to the DB for preparation once (or once per connection)!

Thanks.

StuPointerException
  • 7,117
  • 5
  • 29
  • 54

1 Answers1

4

From the link you provided:

When you enable implicit statement caching, JDBC automatically caches the prepared or callable statement when you call the close method of this statement object.

And

Explicit statement caching enables you to cache and retrieve selected prepared and callable statements. Explicit statement caching relies on a key, an arbitrary Java String that you provide. Because explicit statement caching retains statement data and state as well as metadata, it has a performance edge over implicit statement caching, which retains only metadata. However, you must be cautious when using this type of caching, because explicit statement caching saves all three types of information for reuse and you may not be aware of what data and state are retained from prior use of the statements.

Looks like implicit caching always saves your prepared and callable statements when they're closed, while explicit caching only saves the ones you specify. It also appears that explicit caching may be slightly faster, but carries the risk of returning stale data.

DCookie
  • 42,630
  • 11
  • 83
  • 92