T
- 結果の型 @FunctionalInterface
public interface StatementCallback<T>
executeUpdate
呼び出しや、さまざまな SQL を使用した繰り返しの executeUpdate
呼び出しなど、単一のステートメントで任意の数の操作を実行できます。JdbcTemplate によって内部的に使用されますが、アプリケーションコードにも役立ちます。
JdbcTemplate.execute(StatementCallback)
修飾子と型 | メソッドと説明 |
---|---|
T | doInStatement(java.sql.Statement stmt) アクティブな JDBC ステートメントで JdbcTemplate.execute によって呼び出されます。 |
@Nullable T doInStatement(java.sql.Statement stmt) throws java.sql.SQLException, DataAccessException
JdbcTemplate.execute
によって呼び出されます。ステートメントまたは接続のクローズ、またはトランザクションの処理について気にする必要はありません。これはすべて Spring の JdbcTemplate によって処理されます。 注意 : 開いた ResultSets はすべて、コールバック実装内の finally ブロックで閉じる必要があります。Spring はコールバックが返された後に Statement オブジェクトを閉じますが、これは必ずしも ResultSet リソースが閉じられることを意味するわけではありません: ステートメントオブジェクトは接続プールによってプールされる可能性があり、close
呼び出しはオブジェクトをプールに返すだけで、リソースを物理的に閉じません。
スレッドにバインドされた JDBC トランザクション(DataSourceTransactionManager によって開始された)なしで呼び出された場合、コードはトランザクションセマンティクスを使用して JDBC 接続で実行されます。JTA 対応の DataSource を使用するように JdbcTemplate が構成されている場合、JTA トランザクションがアクティブな場合、JDBC 接続とコールバックコードはトランザクションになります。
コールバック内で作成された結果オブジェクト、つまりドメインオブジェクトまたはドメインオブジェクトのコレクションを返すことができます。シングルステップアクションには特別なサポートがあることに注意してください。JdbcTemplate.queryForObject などを参照してください。スローされた RuntimeException はアプリケーション例外として扱われ、テンプレートの呼び出し元に伝達されます。
stmt
- アクティブな JDBC ステートメント null
java.sql.SQLException
- JDBC メソッドによってスローされた場合、SQLExceptionTranslator によって DataAccessException に自動変換されます。DataAccessException
- カスタム例外の場合 JdbcTemplate.queryForObject(String, Class)
, JdbcTemplate.queryForRowSet(String)