鴻蒙OS StatementEventListener

2022-11-03 10:27 更新

StatementEventListener

  1. public interface StatementEventListener
  2. extends EventListener

一個(gè)對(duì)象,它注冊(cè)以通知在語句池中的 PreparedStatements 上發(fā)生的事件。

JDBC 3.0 規(guī)范添加了 maxStatements ConnectionPooledDataSource 屬性,以提供啟用 PreparedStatements 池的標(biāo)準(zhǔn)機(jī)制并指定語句池的大小。但是,當(dāng) PreparedStatement 無效時(shí),驅(qū)動(dòng)程序無法通知外部語句池。對(duì)于某些數(shù)據(jù)庫,如果執(zhí)行了影響表的 DDL 操作,則語句將變?yōu)闊o效。例如,應(yīng)用程序可能會(huì)創(chuàng)建一個(gè)臨時(shí)表來對(duì)該表執(zhí)行一些工作,然后將其銷毀。它可能會(huì)在以后再次需要時(shí)重新創(chuàng)建同一個(gè)表。某些數(shù)據(jù)庫會(huì)在刪除表時(shí)使引用臨時(shí)表的任何準(zhǔn)備好的語句無效。

與 ConnectionEventListener 接口中定義的方法類似,驅(qū)動(dòng)程序在檢測(cè)到語句無效時(shí)會(huì)在拋出任何異常之前調(diào)用 StatementEventListener.statementErrorOccurred 方法。當(dāng) PreparedStatement 關(guān)閉時(shí),驅(qū)動(dòng)程序還將調(diào)用 StatementEventListener.statementClosed 方法。

允許組件向 PooledConnection 注冊(cè) StatementEventListener 的方法已添加到 PooledConnection 接口中。

Since:

1.6

方法總結(jié)

修飾符和類型 方法 描述
void statementClosed(StatementEvent event) 驅(qū)動(dòng)程序在檢測(cè)到 PreparedStatement 已關(guān)閉時(shí),對(duì)連接上注冊(cè)的所有 StatementEventListener 調(diào)用此方法。
void statementErrorOccurred(StatementEvent event) 驅(qū)動(dòng)程序在檢測(cè)到 PreparedStatement 無效時(shí),對(duì)連接上注冊(cè)的所有 StatementEventListener 調(diào)用此方法。

方法詳情

statementClosed

void statementClosed(StatementEvent event)

驅(qū)動(dòng)程序在檢測(cè)到 PreparedStatement 已關(guān)閉時(shí),對(duì)連接上注冊(cè)的所有 StatementEventListener 調(diào)用此方法。

參數(shù):

參數(shù)名稱 參數(shù)描述
event 描述事件源和 PreparedStatement 已關(guān)閉的事件對(duì)象。

Since:

1.6

statementErrorOccurred

void statementErrorOccurred(StatementEvent event)

驅(qū)動(dòng)程序在檢測(cè)到 PreparedStatement 無效時(shí),對(duì)連接上注冊(cè)的所有 StatementEventListener 調(diào)用此方法。 驅(qū)動(dòng)程序在將給定事件中包含的 SQLException 拋出給應(yīng)用程序之前調(diào)用此方法。

參數(shù):

參數(shù)名稱 參數(shù)描述
event 一個(gè)事件對(duì)象,描述事件的來源、無效的語句以及驅(qū)動(dòng)程序即將拋出的異常。 事件的來源是與無效 PreparedStatement 關(guān)聯(lián)的 PooledConnection。

Since:

1.6

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)