The statement cache is enabled by default. You can use it to avoid extra compilation overhead:
PreparedStatements are JDBC objects that you prepare (compile) once and execute multiple times. See the figure below. If your application executes statements that are almost but not exactly alike, use PreparedStatements, which can contain dynamic or IN parameters. Instead of using the literals for changing parameters, use question marks (?) as placeholders for such parameters. Provide the values when you execute the statement.
When, in the same database, an application submits
an SQL Statement that exactly matches one already in the cache,
To match exactly with a statement already in the cache, the SQL Statement must meet the following requirements: