org.apache.commons.dbutils
クラス QueryRunner

java.lang.Object
  拡張org.apache.commons.dbutils.QueryRunner

public class QueryRunner
extends Object

ResultSet をハンドルするプラグ化可能なストラテジーを持つ SQL の問い合わせを実行します。 このクラスはスレッドセーフです。

Executes SQL queries with pluggable strategies for handling ResultSets. This class is thread safe.

作成者:
Henri Yandell, Juozas Baliuka, Steven Caswell, David Graham
関連項目:
ResultSetHandler
翻訳者:
小川 環
校正者:
日置 聡
翻訳状況:
校正者校正中
翻訳更新日:
2003/12/22

フィールドの概要
protected  DataSource ds
          接続を取り出すためのデータソース。
 
コンストラクタの概要
QueryRunner()
          QueryRunner のコンストラクタ。
QueryRunner(DataSource ds)
          QueryRunnerのコンストラクタ。
 
メソッドの概要
protected  void fillStatement(PreparedStatement stmt, Object[] params)
          PreparedStatement の置換パラメータに、 指定したオブジェクトを埋め込みます。
 DataSource getDataSource()
          このRunnerが使用している DataSource を返します。
protected  PreparedStatement prepareStatement(Connection conn, String sql)
          指定したSQLに対応する PreparedStatement オブジェクトを作成および初期化します。
 Object query(Connection conn, String sql, Object[] params, ResultSetHandler rsh)
          置換パラメータを埋め込んだ SQL SELECT の問い合わせを実行します。
 Object query(Connection conn, String sql, Object param, ResultSetHandler rsh)
          単一の置換パラメータを埋め込んだ SQL SELECT の問い合わせを実行します。
 Object query(Connection conn, String sql, ResultSetHandler rsh)
          置換パラメータが一切含まれない SQL SELECT の問い合わせを実行します。
 Object query(String sql, Object[] params, ResultSetHandler rsh)
          指定された SQL SELECT を実行し、結果を格納したオブジェクトを返します。
 Object query(String sql, Object param, ResultSetHandler rsh)
          単一の置換パラメータを含む、指定された SQL SELECT を実行します。
 Object query(String sql, ResultSetHandler rsh)
          指定された SQL SELECT を置換パラメータなしで実行します。
protected  void rethrow(SQLException cause, String sql, Object[] params)
          さらに有益なエラーメッセージを含む新規の例外をスローします
Throws a new exception with a more informative error message.
 void setDataSource(DataSource dataSource)
          この Runner がデータベース接続を取得するのに使用する DataSource をセットします。
 int update(Connection conn, String sql)
          置換パラメータのない SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
 int update(Connection conn, String sql, Object param)
          単一の置換パラメータを埋め込んだ SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
 int update(Connection conn, String sql, Object[] params)
          SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
 int update(String sql)
          置換パラメータを含まない、指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
 int update(String sql, Object param)
          単一の置換パラメータを含む、指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
 int update(String sql, Object[] params)
          指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
protected  ResultSet wrap(ResultSet rs)
          ResultSet を処理する前に、デコレータによってラップします。
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

ds

protected DataSource ds
接続を取り出すためのデータソース。
The DataSource to retrieve connections from.

コンストラクタの詳細

QueryRunner

public QueryRunner()
QueryRunner のコンストラクタ。
Constructor for QueryRunner.


QueryRunner

public QueryRunner(DataSource ds)
QueryRunnerのコンストラクタ。 Connection パラメータを使用しないメソッドでは、 この DataSource から接続を取り出します。
Constructor for QueryRunner. Methods that do not take a Connection parameter will retrieve connections from this DataSource.

パラメータ:
ds - 接続を取り出すためのデータソース。
The DataSource to retrieve connections from.
メソッドの詳細

fillStatement

protected void fillStatement(PreparedStatement stmt,
                             Object[] params)
                      throws SQLException
PreparedStatement の置換パラメータに、 指定したオブジェクトを埋め込みます。
Fill the PreparedStatement replacement parameters with the given objects.

パラメータ:
stmt -
params - 問い合わせの置換パラメータ。 null は有効な値として通過されます。
Query replacement parameters; null is a valid value to pass in.
例外:
SQLException

getDataSource

public DataSource getDataSource()
このRunnerが使用している DataSource を返します。
Returns the DataSource this runner is using.


prepareStatement

protected PreparedStatement prepareStatement(Connection conn,
                                             String sql)
                                      throws SQLException
指定したSQLに対応する PreparedStatement オブジェクトを作成および初期化します。 QueryRunner のメソッドはステートメントを準備するのにこのメソッドを常に呼び出します。 必要であれば、PreparedStatement の特別なコンフィグレーションを提供するためにこのメソッドをサブクラスでオーバーライド可能です。 この実装は、ただ単純に conn.prepareStatement(sql) を呼び出します。
Factory method that creates and initializes a PreparedStatement object for the given SQL. QueryRunner methods always call this method to prepare statements for them. Subclasses can override this method to provide special PreparedStatement configuration if needed. This implementation simply calls conn.prepareStatement(sql).

パラメータ:
conn - PreparedStatement を作成するために使用する Connection
The Connection used to create the PreparedStatement
sql - 準備対象の SQL ステートメント。
The SQL statement to prepare.
戻り値:
初期化された PreparedStatement
An initialized PreparedStatement.
例外:
SQLException

query

public Object query(Connection conn,
                    String sql,
                    Object param,
                    ResultSetHandler rsh)
             throws SQLException
単一の置換パラメータを埋め込んだ SQL SELECT の問い合わせを実行します。 呼び出し側では、接続の解放処理が課せられます。
Execute an SQL SELECT query with a single replacement parameter. The caller is responsible for connection cleanup.

パラメータ:
conn - 問い合わせを実行する接続。
The connection to execute the query in.
sql - 実行する問い合わせ。
The query to execute.
param - 置換パラメータ。
The replacement parameter.
rsh - 結果をオブジェクトに変換するハンドラ。
The handler that converts the results into an object.
戻り値:
ハンドラによって返されるオブジェクト。
The object returned by the handler.
例外:
SQLException

query

public Object query(Connection conn,
                    String sql,
                    Object[] params,
                    ResultSetHandler rsh)
             throws SQLException
置換パラメータを埋め込んだ SQL SELECT の問い合わせを実行します。 呼び出し側では、接続の解放処理が課せられます。
Execute an SQL SELECT query with replacement parameters. The caller is responsible for connection cleanup.

パラメータ:
conn - 問い合わせを実行する接続。
The connection to execute the query in.
sql - 実行する問い合わせ。
The query to execute.
params - 置換パラメータ。
The replacement parameters.
rsh - 結果をオブジェクトに変換するハンドラ。
The handler that converts the results into an object.
戻り値:
ハンドラによって返されるオブジェクト。
The object returned by the handler.
例外:
SQLException

query

public Object query(Connection conn,
                    String sql,
                    ResultSetHandler rsh)
             throws SQLException
置換パラメータが一切含まれない SQL SELECT の問い合わせを実行します。 呼び出し側では、接続の解放処理が課せられます。
Execute an SQL SELECT query without any replacement parameters. The caller is responsible for connection cleanup.

パラメータ:
conn - 問い合わせを実行する接続。
The connection to execute the query in.
sql - 実行する問い合わせ。
The query to execute.
rsh - 結果をオブジェクトに変換するハンドラ。
The handler that converts the results into an object.
戻り値:
ハンドラによって返されるオブジェクト。
The object returned by the handler.
例外:
SQLException

query

public Object query(String sql,
                    Object param,
                    ResultSetHandler rsh)
             throws SQLException
単一の置換パラメータを含む、指定された SQL SELECT を実行します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given SELECT SQL with a single replacement parameter. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQLステートメント。
The SQL statement to execute.
param - 置換パラメータ。
The replacement parameter.
rsh - ResultSet から結果を格納したオブジェクトを作成するために使用されるハンドラ。
The handler used to create the result object from the ResultSet.
戻り値:
ハンドラによって生成されるオブジェクト。
An object generated by the handler.
例外:
SQLException

query

public Object query(String sql,
                    Object[] params,
                    ResultSetHandler rsh)
             throws SQLException
指定された SQL SELECT を実行し、結果を格納したオブジェクトを返します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given SELECT SQL query and returns a result object. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQLステートメント。
The SQL statement to execute.
params - この配列とともにPreparedStatementのINパラメータを初期化します。
Initialize the PreparedStatement's IN parameters with this array.
rsh - ResultSet から結果を格納したオブジェクトを作成するために使用されるハンドラ。
The handler used to create the result object from the ResultSet.
戻り値:
ハンドラによって生成されるオブジェクト。
An object generated by the handler.
例外:
SQLException

query

public Object query(String sql,
                    ResultSetHandler rsh)
             throws SQLException
指定された SQL SELECT を置換パラメータなしで実行します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given SELECT SQL without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQLステートメント。
The SQL statement to execute.
rsh - ResultSet から結果を格納したオブジェクトを作成するために使用されるハンドラ。
The handler used to create the result object from the ResultSet.
戻り値:
ハンドラによって生成されるオブジェクト。
An object generated by the handler.
例外:
SQLException

rethrow

protected void rethrow(SQLException cause,
                       String sql,
                       Object[] params)
                throws SQLException
さらに有益なエラーメッセージを含む新規の例外をスローします
Throws a new exception with a more informative error message.

パラメータ:
cause - 再スローされる際に、新規の例外へチェーンされる根本的な例外。
The original exception that will be chained to the new exception when it's rethrown.
sql - 例外発生時に実行した問い合わせ。
The query that was executing when the exception happened.
params - 問い合わせの置換パラメータ。 null は有効な値として通過されます。
The query replacement paramaters; null is a valid value to pass in.
例外:
SQLException

setDataSource

public void setDataSource(DataSource dataSource)
この Runner がデータベース接続を取得するのに使用する DataSource をセットします。 Connection を渡さない状態で、実行メソッドを使用するつもりであれば、 デフォルトコンストラクタを含め Runner が作成した後、これを呼び出すようにすべきです。
Sets the DataSource this runner will use to get database connections from. This should be called after creating a runner with the default constructor if you intend to use the execute methods without passing in a Connection.

パラメータ:
dataSource - 使用するデータソース。
The DataSource to use.

update

public int update(Connection conn,
                  String sql)
           throws SQLException
置換パラメータのない SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
Execute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.

パラメータ:
conn - 問い合わせを実行するのに使用する接続。
The connection to use to run the query.
sql - 実行するSQL。
The SQL to execute.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

update

public int update(Connection conn,
                  String sql,
                  Object param)
           throws SQLException
単一の置換パラメータを埋め込んだ SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.

パラメータ:
conn - 問い合わせを実行するのに使用する接続。
The connection to use to run the query.
sql - 実行するSQL。
The SQL to execute.
param - 置換パラメータ。
The replacement parameter.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

update

public int update(Connection conn,
                  String sql,
                  Object[] params)
           throws SQLException
SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。
Execute an SQL INSERT, UPDATE, or DELETE query.

パラメータ:
conn - 問い合わせを実行するのに使用する接続。
The connection to use to run the query.
sql - 実行するSQL。
The SQL to execute.
params - 置換パラメータ。
The query replacement parameters.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

update

public int update(String sql)
           throws SQLException
置換パラメータを含まない、指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQL文。
The SQL statement to execute.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

update

public int update(String sql,
                  Object param)
           throws SQLException
単一の置換パラメータを含む、指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQL文。
The SQL statement to execute.
param - 置換パラメータ。
The replacement parameter.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

update

public int update(String sql,
                  Object[] params)
           throws SQLException
指定された SQL INSERT、UPDATE、または、DELETE の問い合わせを実行します。 Connection は、コンストラクタでセットされた DataSource から取り出されます。
Executes the given INSERT, UPDATE, or DELETE SQL statement. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - 実行するSQL文。
The SQL statement to execute.
params - PreparedStatement の IN (例. '?')パラメータを初期化します。
Initializes the PreparedStatement's IN (i.e. '?') parameters.
戻り値:
更新した行数。
The number of rows updated.
例外:
SQLException

wrap

protected ResultSet wrap(ResultSet rs)
ResultSet を処理する前に、デコレータによってラップします。 この実装は、デコレーションが施された状態でない限り、与えられた ResultSet を返します。
Wrap the ResultSet in a decorator before processing it. This implementation returns the ResultSet it is given without any decoration.

多くの場合、このメソッドの実装はこのように無名インナークラスの中でラップされます。

Often, the implementation of this method can be done in an anonymous inner class like this:

 
 QueryRunner run = new QueryRunner() {
     protected ResultSet wrap(ResultSet rs) {
         return StringTrimmedResultSet.wrap(rs);
     }
 };
 

パラメータ:
rs - デコレーションを施す ResultSetnull ではいけません。
The ResultSet to decorate; never null.
戻り値:
デコレータによってラップされた ResultSet
The ResultSet wrapped in some decorator.


このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation