org.apache.commons.dbutils
クラス QueryRunner

java.lang.Object
  上位を拡張 org.apache.commons.dbutils.QueryRunner

public class QueryRunner
extends java.lang.Object

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

関連項目:
ResultSetHandler

コンストラクタの概要
QueryRunner()
          Constructor for QueryRunner.
QueryRunner(javax.sql.DataSource ds)
          Constructor for QueryRunner.
 
メソッドの概要
 int[] batch(java.sql.Connection conn, java.lang.String sql, java.lang.Object[][] params)
          Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
 int[] batch(java.lang.String sql, java.lang.Object[][] params)
          Execute a batch of SQL INSERT, UPDATE, or DELETE queries.
 javax.sql.DataSource getDataSource()
          Returns the DataSource this runner is using.
 java.lang.Object query(java.sql.Connection conn, java.lang.String sql, java.lang.Object[] params, ResultSetHandler rsh)
          Execute an SQL SELECT query with replacement parameters.
 java.lang.Object query(java.sql.Connection conn, java.lang.String sql, java.lang.Object param, ResultSetHandler rsh)
          Execute an SQL SELECT query with a single replacement parameter.
 java.lang.Object query(java.sql.Connection conn, java.lang.String sql, ResultSetHandler rsh)
          Execute an SQL SELECT query without any replacement parameters.
 java.lang.Object query(java.lang.String sql, java.lang.Object[] params, ResultSetHandler rsh)
          Executes the given SELECT SQL query and returns a result object.
 java.lang.Object query(java.lang.String sql, java.lang.Object param, ResultSetHandler rsh)
          Executes the given SELECT SQL with a single replacement parameter.
 java.lang.Object query(java.lang.String sql, ResultSetHandler rsh)
          Executes the given SELECT SQL without any replacement parameters.
 void setDataSource(javax.sql.DataSource dataSource)
          Sets the DataSource this runner will use to get database connections from.
 int update(java.sql.Connection conn, java.lang.String sql)
          Execute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.
 int update(java.sql.Connection conn, java.lang.String sql, java.lang.Object param)
          Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.
 int update(java.sql.Connection conn, java.lang.String sql, java.lang.Object[] params)
          Execute an SQL INSERT, UPDATE, or DELETE query.
 int update(java.lang.String sql)
          Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters.
 int update(java.lang.String sql, java.lang.Object param)
          Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter.
 int update(java.lang.String sql, java.lang.Object[] params)
          Executes the given INSERT, UPDATE, or DELETE SQL statement.
 
クラス java.lang.Object から継承されたメソッド
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

コンストラクタの詳細

QueryRunner

public QueryRunner()
Constructor for QueryRunner.


QueryRunner

public QueryRunner(javax.sql.DataSource ds)
Constructor for QueryRunner. Methods that do not take a Connection parameter will retrieve connections from this DataSource.

パラメータ:
ds - The DataSource to retrieve connections from.
メソッドの詳細

batch

public int[] batch(java.sql.Connection conn,
                   java.lang.String sql,
                   java.lang.Object[][] params)
            throws java.sql.SQLException
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.

パラメータ:
conn - The Connection to use to run the query. The caller is responsible for closing this Connection.
sql - The SQL to execute.
params - An array of query replacement parameters. Each row in this array is one set of batch replacement values.
戻り値:
The number of rows updated per statement.
例外:
java.sql.SQLException - if a database access error occurs
導入されたバージョン:
DbUtils 1.1

batch

public int[] batch(java.lang.String sql,
                   java.lang.Object[][] params)
            throws java.sql.SQLException
Execute a batch of SQL INSERT, UPDATE, or DELETE queries. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.

パラメータ:
sql - The SQL to execute.
params - An array of query replacement parameters. Each row in this array is one set of batch replacement values.
戻り値:
The number of rows updated per statement.
例外:
java.sql.SQLException - if a database access error occurs
導入されたバージョン:
DbUtils 1.1

getDataSource

public javax.sql.DataSource getDataSource()
Returns the DataSource this runner is using. QueryRunner methods always call this method to get the DataSource so subclasses can provide specialized behavior.

戻り値:
DataSource the runner is using

query

public java.lang.Object query(java.sql.Connection conn,
                              java.lang.String sql,
                              java.lang.Object param,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Execute an SQL SELECT query with a single replacement parameter. The caller is responsible for closing the connection.

パラメータ:
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.
例外:
java.sql.SQLException - if a database access error occurs

query

public java.lang.Object query(java.sql.Connection conn,
                              java.lang.String sql,
                              java.lang.Object[] params,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Execute an SQL SELECT query with replacement parameters. The caller is responsible for closing the connection.

パラメータ:
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.
例外:
java.sql.SQLException - if a database access error occurs

query

public java.lang.Object query(java.sql.Connection conn,
                              java.lang.String sql,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Execute an SQL SELECT query without any replacement parameters. The caller is responsible for closing the connection.

パラメータ:
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.
例外:
java.sql.SQLException - if a database access error occurs

query

public java.lang.Object query(java.lang.String sql,
                              java.lang.Object param,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Executes the given SELECT SQL with a single replacement parameter. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - The SQL statement to execute.
param - The replacement parameter.
rsh - The handler used to create the result object from the ResultSet.
戻り値:
An object generated by the handler.
例外:
java.sql.SQLException - if a database access error occurs

query

public java.lang.Object query(java.lang.String sql,
                              java.lang.Object[] params,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Executes the given SELECT SQL query and returns a result object. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - The SQL statement to execute.
params - Initialize the PreparedStatement's IN parameters with this array.
rsh - The handler used to create the result object from the ResultSet.
戻り値:
An object generated by the handler.
例外:
java.sql.SQLException - if a database access error occurs

query

public java.lang.Object query(java.lang.String sql,
                              ResultSetHandler rsh)
                       throws java.sql.SQLException
Executes the given SELECT SQL without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor.

パラメータ:
sql - The SQL statement to execute.
rsh - The handler used to create the result object from the ResultSet.
戻り値:
An object generated by the handler.
例外:
java.sql.SQLException - if a database access error occurs

setDataSource

public void setDataSource(javax.sql.DataSource dataSource)
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(java.sql.Connection conn,
                  java.lang.String sql)
           throws java.sql.SQLException
Execute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.

パラメータ:
conn - The connection to use to run the query.
sql - The SQL to execute.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs

update

public int update(java.sql.Connection conn,
                  java.lang.String sql,
                  java.lang.Object param)
           throws java.sql.SQLException
Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.

パラメータ:
conn - The connection to use to run the query.
sql - The SQL to execute.
param - The replacement parameter.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs

update

public int update(java.sql.Connection conn,
                  java.lang.String sql,
                  java.lang.Object[] params)
           throws java.sql.SQLException
Execute an SQL INSERT, UPDATE, or DELETE query.

パラメータ:
conn - The connection to use to run the query.
sql - The SQL to execute.
params - The query replacement parameters.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.String sql)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.

パラメータ:
sql - The SQL statement to execute.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.String sql,
                  java.lang.Object param)
           throws java.sql.SQLException
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. This Connection must be in auto-commit mode or the update will not be saved.

パラメータ:
sql - The SQL statement to execute.
param - The replacement parameter.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs

update

public int update(java.lang.String sql,
                  java.lang.Object[] params)
           throws java.sql.SQLException
Executes the given INSERT, UPDATE, or DELETE SQL statement. The Connection is retrieved from the DataSource set in the constructor. This Connection must be in auto-commit mode or the update will not be saved.

パラメータ:
sql - The SQL statement to execute.
params - Initializes the PreparedStatement's IN (i.e. '?') parameters.
戻り値:
The number of rows updated.
例外:
java.sql.SQLException - if a database access error occurs