Cursor representation:
A cursor is associated both with the PreparedStatement and the Statement class, however, only the PreparedStatement class can be used to separate the parse from the execute.
Parse call
During the first call of the execute() or executeQuery() method, the statement (of class PreparedStatement) will be parsed. Subsequent calls to execute() or executeQuery() will not do parsing.
Binding
Placeholders in SQL statements are specified using ‘?’ and binding is done by value. Therefore, appropriate setXXX() methods must be called before each execute.
Execute call
Execution is done with the execute() or executeQuery() method.
Array processing JDBC automatically buffers rows for fetch operations. Array inserts are not supported.
Best practice
You should open the PreparedStatement object using the SQL statement, and repeat the execute() or executeQuery() method as often as needed. If the close() method is called, it must be re-opened and hence, a parse of the SQL statement will take place. Using statement caching, you can alternatively call the close() method and repeat the open() call with an identical SQL statement text. As long as the statement cache is not exhausted, any open() with a SQL statement found in the cache will actually use the parsed statement in the cache and the subsequent call to the execute() or executeQuery() method will not do a parse.
Special considerations
The Statement class should only be used for SQL statements that are very infrequently or not at all repeated. The parse and execute steps will always be done at the same time when the Statement class is used
Partager