Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
Jaybird 2.1 JDBC driver Java Programmer's Manual - Firebird
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
• Compile the SQL statement into an internal BLR representation, save it in an<br />
internal structure and assign a statement handle to a compiled statement.<br />
• Execute the statement. First application checks whether the compiled statement<br />
has any parameters and sets them if needed. After that statement is executed<br />
using special call.<br />
• Obtain results of the statement execution, for example number of updated rows<br />
or a result set.<br />
The obvious approach is to save the compiled statement and use it later. <strong>JDBC</strong><br />
specification already contains a java.sql.PreparedStatement interface exactly<br />
for such purposes. Application prepares statement and uses it multiple times. This<br />
approach works fine within the context of the same connection.<br />
However, when connection pooling is used, application can no longer cache<br />
prepared statements, since they are bound to the connection it obtained from the<br />
pool. Application must close all prepared statements before giving connection<br />
back to pool, but even if it does not do this, connection pool will perform this<br />
automatically according to the <strong>JDBC</strong> specification. All advantages of the prepared<br />
statements are undone – when application obtains next connection from the pool,<br />
it must re-prepare statements.<br />
Solution to the problem is to allow connection pool do statement pooling<br />
internally. In this case all code remains compliant with the <strong>JDBC</strong> specification<br />
saving all advantages of prepared statements.<br />
<strong>Jaybird</strong> <strong>2.1</strong> connection pool has maxStatements property that controls the<br />
behavior of the prepared statement pooling:<br />
• If property is set to 0, no statement pooling is performed.<br />
• If property is set to value n>0, connection pool will save maximum n<br />
java.sql.PreparedStatement objects for the same SQL statement per<br />
connection. Number of pooled PreparedStatement objects corresponding to<br />
different SQL statements is not limited.<br />
If application needs more prepared statements simultaneously (i.e. it prepares new<br />
statement before releasing the one being currently in use), connection pool<br />
transparently passes call to the connection object without pooling those<br />
statements. In other words, the request to prepare statement is always satisfied<br />
immediately, but only n prepared statements will remain pooled, rest will be<br />
deallocated when PreparedStatement.close() method is called.<br />
Following limitations apply:<br />
• <strong>Firebird</strong> can have approx. 20.000 active statement handles per connection.<br />
Additional care should be used when specifying the value of maxStatements<br />
property.<br />
• Neither java.sql.Statement nor java.sql.CallableStatement objects are<br />
pooled.<br />
• A compiled statement in <strong>Firebird</strong> contains references on database objects<br />
(tables, views, procedures, etc.) needed to execute that SQL command. When<br />
connection pool is used, those references are not released preventing any<br />
structure modification of the database objects used in the SQL statement.<br />
Chapter 4. Executing statements 42