阅读(923) (0)

鸿蒙OS StatementEventListener

2022-11-02 10:17:14 更新

StatementEventListener

public interface StatementEventListener
extends EventListener

一个对象,它注册以通知在语句池中的 PreparedStatements 上发生的事件。

JDBC 3.0 规范添加了 maxStatements ConnectionPooledDataSource 属性,以提供启用 PreparedStatements 池的标准机制并指定语句池的大小。但是,当 PreparedStatement 无效时,驱动程序无法通知外部语句池。对于某些数据库,如果执行了影响表的 DDL 操作,则语句将变为无效。例如,应用程序可能会创建一个临时表来对该表执行一些工作,然后将其销毁。它可能会在以后再次需要时重新创建同一个表。某些数据库会在删除表时使引用临时表的任何准备好的语句无效。

与 ConnectionEventListener 接口中定义的方法类似,驱动程序在检测到语句无效时会在抛出任何异常之前调用 StatementEventListener.statementErrorOccurred 方法。当 PreparedStatement 关闭时,驱动程序还将调用 StatementEventListener.statementClosed 方法。

允许组件向 PooledConnection 注册 StatementEventListener 的方法已添加到 PooledConnection 接口中。

Since:

1.6

方法总结

修饰符和类型 方法 描述
void statementClosed(StatementEvent event) 驱动程序在检测到 PreparedStatement 已关闭时,对连接上注册的所有 StatementEventListener 调用此方法。
void statementErrorOccurred(StatementEvent event) 驱动程序在检测到 PreparedStatement 无效时,对连接上注册的所有 StatementEventListener 调用此方法。

方法详情

statementClosed

void statementClosed(StatementEvent event)

驱动程序在检测到 PreparedStatement 已关闭时,对连接上注册的所有 StatementEventListener 调用此方法。

参数:

参数名称 参数描述
event 描述事件源和 PreparedStatement 已关闭的事件对象。

Since:

1.6

statementErrorOccurred

void statementErrorOccurred(StatementEvent event)

驱动程序在检测到 PreparedStatement 无效时,对连接上注册的所有 StatementEventListener 调用此方法。 驱动程序在将给定事件中包含的 SQLException 抛出给应用程序之前调用此方法。

参数:

参数名称 参数描述
event 一个事件对象,描述事件的来源、无效的语句以及驱动程序即将抛出的异常。 事件的来源是与无效 PreparedStatement 关联的 PooledConnection。

Since:

1.6