PreparedStatements are JDBC objects that you prepare (compile) once and execute multiple times. (See Figure1.) 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, Derby grabs the statement from the cache, even if the Statement has already been closed by the application.
To match exactly with a statement already in the cache, the SQL Statement must meet the following requirements: