StatementEventListener
Stay organized with collections
Save and categorize content based on your preferences.
An object that registers to be notified of events that occur on PreparedStatements
that are in the Statement pool.
The JDBC 3.0 specification added the maxStatements
ConnectionPooledDataSource
property to provide a standard mechanism for
enabling the pooling of PreparedStatements
and to specify the size of the statement
pool. However, there was no way for a driver to notify an external
statement pool when a PreparedStatement
becomes invalid. For some databases, a
statement becomes invalid if a DDL operation is performed that affects the
table. For example an application may create a temporary table to do some work
on the table and then destroy it. It may later recreate the same table when
it is needed again. Some databases will invalidate any prepared statements
that reference the temporary table when the table is dropped.
Similar to the methods defined in the ConnectionEventListener
interface,
the driver will call the StatementEventListener.statementErrorOccurred
method prior to throwing any exceptions when it detects a statement is invalid.
The driver will also call the StatementEventListener.statementClosed
method when a PreparedStatement
is closed.
Methods which allow a component to register a StatementEventListener with a
PooledConnection
have been added to the PooledConnection
interface.
Public Method Summary
abstract
void
|
statementClosed( StatementEvent event)
The driver calls this method on all StatementEventListener s registered on the connection when it detects that a
PreparedStatement is closed.
|
abstract
void
|
statementErrorOccurred( StatementEvent event)
The driver calls this method on all StatementEventListener s
registered on the connection when it detects that a
PreparedStatement is invalid.
|
Public Methods
public
abstract
void
statementClosed
(StatementEvent event)
The driver calls this method on all StatementEventListener
s registered on the connection when it detects that a
PreparedStatement
is closed.
Parameters
event |
an event object describing the source of
the event and that the PreparedStatement was closed. |
public
abstract
void
statementErrorOccurred
(StatementEvent event)
The driver calls this method on all StatementEventListener
s
registered on the connection when it detects that a
PreparedStatement
is invalid. The driver calls this method
just before it throws the SQLException
,
contained in the given event, to the application.
Parameters
event |
an event object describing the source of the event,
the statement that is invalid and the exception the
driver is about to throw. The source of the event is
the PooledConnection which the invalid PreparedStatement
is associated with.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eStatementEventListener\u003c/code\u003e enables notification of events related to \u003ccode\u003ePreparedStatements\u003c/code\u003e in a statement pool.\u003c/p\u003e\n"],["\u003cp\u003eDrivers utilize this interface to inform about statement closure and errors, especially when a \u003ccode\u003ePreparedStatement\u003c/code\u003e becomes invalid due to database changes like DDL operations.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estatementClosed()\u003c/code\u003e is invoked when a \u003ccode\u003ePreparedStatement\u003c/code\u003e is closed.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003estatementErrorOccurred()\u003c/code\u003e is called before an exception is thrown, indicating an invalid \u003ccode\u003ePreparedStatement\u003c/code\u003e, often due to database structure changes impacting the statement's validity.\u003c/p\u003e\n"]]],["`StatementEventListener` allows notification of events on `PreparedStatements` in a statement pool. Drivers call `statementClosed` when a `PreparedStatement` is closed and `statementErrorOccurred` when a statement becomes invalid, prior to throwing an exception. This addresses the issue of external statement pool not receiving notification when a `PreparedStatement` is invalidated, such as after a DDL operation. Components register listeners via `PooledConnection`. The two methods `statementClosed` and `statementErrorOccurred` take a `StatementEvent` parameter.\n"],null,["# StatementEventListener\n\npublic interface **StatementEventListener** implements [EventListener](../../../reference/java/util/EventListener.html) \nAn object that registers to be notified of events that occur on PreparedStatements\nthat are in the Statement pool.\n\n\nThe JDBC 3.0 specification added the maxStatements\n`ConnectionPooledDataSource` property to provide a standard mechanism for\nenabling the pooling of `PreparedStatements`\nand to specify the size of the statement\npool. However, there was no way for a driver to notify an external\nstatement pool when a `PreparedStatement` becomes invalid. For some databases, a\nstatement becomes invalid if a DDL operation is performed that affects the\ntable. For example an application may create a temporary table to do some work\non the table and then destroy it. It may later recreate the same table when\nit is needed again. Some databases will invalidate any prepared statements\nthat reference the temporary table when the table is dropped.\n\n\nSimilar to the methods defined in the `ConnectionEventListener` interface,\nthe driver will call the `StatementEventListener.statementErrorOccurred`\nmethod prior to throwing any exceptions when it detects a statement is invalid.\nThe driver will also call the `StatementEventListener.statementClosed`\nmethod when a `PreparedStatement` is closed.\n\n\nMethods which allow a component to register a StatementEventListener with a\n`PooledConnection` have been added to the `PooledConnection` interface.\n\n\u003cbr /\u003e\n\n### Public Method Summary\n\n|---------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract void | [statementClosed](../../../reference/javax/sql/StatementEventListener.html#statementClosed(javax.sql.StatementEvent))([StatementEvent](../../../reference/javax/sql/StatementEvent.html) event) The driver calls this method on all `StatementEventListener`s registered on the connection when it detects that a `PreparedStatement` is closed. |\n| abstract void | [statementErrorOccurred](../../../reference/javax/sql/StatementEventListener.html#statementErrorOccurred(javax.sql.StatementEvent))([StatementEvent](../../../reference/javax/sql/StatementEvent.html) event) The driver calls this method on all `StatementEventListener`s registered on the connection when it detects that a `PreparedStatement` is invalid. |\n\nPublic Methods\n--------------\n\n#### public abstract void\n**statementClosed**\n([StatementEvent](../../../reference/javax/sql/StatementEvent.html) event)\n\nThe driver calls this method on all `StatementEventListener`s registered on the connection when it detects that a\n`PreparedStatement` is closed. \n\n##### Parameters\n\n| event | an event object describing the source of the event and that the `PreparedStatement` was closed. |\n|-------|-------------------------------------------------------------------------------------------------|\n\n#### public abstract void\n**statementErrorOccurred**\n([StatementEvent](../../../reference/javax/sql/StatementEvent.html) event)\n\nThe driver calls this method on all `StatementEventListener`s\nregistered on the connection when it detects that a\n`PreparedStatement` is invalid. The driver calls this method\njust before it throws the `SQLException`,\ncontained in the given event, to the application.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| event | an event object describing the source of the event, the statement that is invalid and the exception the driver is about to throw. The source of the event is the `PooledConnection` which the invalid `PreparedStatement` is associated with. \u003cbr /\u003e |\n|-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|"]]