QueryRunner的API
Class QueryRunner
- java.lang.Object
- org.apache.commons.dbutils.AbstractQueryRunner
- org.apache.commons.dbutils.QueryRunner
public class QueryRunner
extends AbstractQueryRunnerExecutes SQL queries with pluggable strategies for handlingResultSet
s. This class is thread safe.- See Also:
ResultSetHandler
Field Summary
Fields inherited from class org.apache.commons.dbutils.AbstractQueryRunner
Constructor Summary
Constructors Constructor and Description QueryRunner()
Constructor for QueryRunner.QueryRunner(boolean pmdKnownBroken)
Constructor for QueryRunner that controls the use ofParameterMetaData
.QueryRunner(DataSource ds)
Constructor for QueryRunner that takes aDataSource
to use.QueryRunner(DataSource ds, boolean pmdKnownBroken)
Constructor for QueryRunner that takes aDataSource
and controls the use ofParameterMetaData
.
Method Summary
Methods Modifier and Type Method and Description int[]
batch(Connection conn, String sql, Object[][] params)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.int[]
batch(String sql, Object[][] params)
Execute a batch of SQL INSERT, UPDATE, or DELETE queries.<T> T
insert(Connection conn, String sql, ResultSetHandler<T> rsh)
Execute an SQL INSERT query without replacement parameters.<T> T
insert(Connection conn, String sql, ResultSetHandler<T> rsh, Object... params)
Execute an SQL INSERT query.<T> T
insert(String sql, ResultSetHandler<T> rsh)
Executes the given INSERT SQL without any replacement parameters.<T> T
insert(String sql, ResultSetHandler<T> rsh, Object... params)
Executes the given INSERT SQL statement.<T> T
insertBatch(Connection conn, String sql, ResultSetHandler<T> rsh, Object[][] params)
Executes the given batch of INSERT SQL statements.<T> T
insertBatch(String sql, ResultSetHandler<T> rsh, Object[][] params)
Executes the given batch of INSERT SQL statements.<T> T
query(Connection conn, String sql, Object[] params, ResultSetHandler<T> rsh)
Deprecated.<T> T
query(Connection conn, String sql, Object param, ResultSetHandler<T> rsh)
Deprecated.<T> T
query(Connection conn, String sql, ResultSetHandler<T> rsh)
Execute an SQL SELECT query without any replacement parameters.<T> T
query(Connection conn, String sql, ResultSetHandler<T> rsh, Object... params)
Execute an SQL SELECT query with replacement parameters.<T> T
query(String sql, Object[] params, ResultSetHandler<T> rsh)
Deprecated.<T> T
query(String sql, Object param, ResultSetHandler<T> rsh)
Deprecated.<T> T
query(String sql, ResultSetHandler<T> rsh)
Executes the given SELECT SQL without any replacement parameters.<T> T
query(String sql, ResultSetHandler<T> rsh, Object... params)
Executes the given SELECT SQL query and returns a result object.int
update(Connection conn, String sql)
Execute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.int
update(Connection conn, String sql, Object... params)
Execute an SQL INSERT, UPDATE, or DELETE query.int
update(Connection conn, String sql, Object param)
Execute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.int
update(String sql)
Executes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters.int
update(String sql, Object... params)
Executes the given INSERT, UPDATE, or DELETE SQL statement.int
update(String sql, Object param)
Executes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter.Methods inherited from class org.apache.commons.dbutils.AbstractQueryRunner
close, close, close, fillStatement, fillStatementWithBean, fillStatementWithBean, getDataSource, isPmdKnownBroken, prepareConnection, prepareStatement, prepareStatement, rethrow, wrap
Constructor Detail
QueryRunner
public QueryRunner()
Constructor for QueryRunner.
QueryRunner
public QueryRunner(boolean pmdKnownBroken)
Constructor for QueryRunner that controls the use ofParameterMetaData
.- Parameters:
pmdKnownBroken
- Some drivers don't supportParameterMetaData.getParameterType(int)
; ifpmdKnownBroken
is set to true, we won't even try it; if false, we'll try it, and if it breaks, we'll remember not to use it again.
QueryRunner
public QueryRunner(DataSource ds)
Constructor for QueryRunner that takes aDataSource
to use. Methods that do not take aConnection
parameter will retrieve connections from thisDataSource
.- Parameters:
ds
- TheDataSource
to retrieve connections from.
QueryRunner
public QueryRunner(DataSource ds,
boolean pmdKnownBroken)Constructor for QueryRunner that takes aDataSource
and controls the use ofParameterMetaData
. Methods that do not take aConnection
parameter will retrieve connections from thisDataSource
.- Parameters:
ds
- TheDataSource
to retrieve connections from.pmdKnownBroken
- Some drivers don't supportParameterMetaData.getParameterType(int)
; ifpmdKnownBroken
is set to true, we won't even try it; if false, we'll try it, and if it breaks, we'll remember not to use it again.
Method Detail
batch
public int[] batch(Connection conn,
String sql,
Object[][] params)
throws SQLExceptionExecute a batch of SQL INSERT, UPDATE, or DELETE queries.- Parameters:
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.- Returns:
- The number of rows updated per statement.
- Throws:
SQLException
- if a database access error occurs- Since:
- DbUtils 1.1
batch
public int[] batch(String sql,
Object[][] params)
throws SQLExceptionExecute a batch of SQL INSERT, UPDATE, or DELETE queries. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the update will not be saved.- Parameters:
sql
- The SQL to execute.params
- An array of query replacement parameters. Each row in this array is one set of batch replacement values.- Returns:
- The number of rows updated per statement.
- Throws:
SQLException
- if a database access error occurs- Since:
- DbUtils 1.1
query
@Deprecated
public <T> T query(Connection conn,
String sql,
Object param,
ResultSetHandler<T> rsh)
throws SQLExceptionDeprecated. Usequery(Connection, String, ResultSetHandler, Object...)
Execute an SQL SELECT query with a single replacement parameter. The caller is responsible for closing the connection.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
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.- Returns:
- The object returned by the handler.
- Throws:
SQLException
- if a database access error occurs
query
@Deprecated
public <T> T query(Connection conn,
String sql,
Object[] params,
ResultSetHandler<T> rsh)
throws SQLExceptionDeprecated. Usequery(Connection,String,ResultSetHandler,Object...)
insteadExecute an SQL SELECT query with replacement parameters. The caller is responsible for closing the connection.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
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.- Returns:
- The object returned by the handler.
- Throws:
SQLException
- if a database access error occurs
query
public <T> T query(Connection conn,
String sql,
ResultSetHandler<T> rsh,
Object... params)
throws SQLExceptionExecute an SQL SELECT query with replacement parameters. The caller is responsible for closing the connection.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
conn
- The connection to execute the query in.sql
- The query to execute.rsh
- The handler that converts the results into an object.params
- The replacement parameters.- Returns:
- The object returned by the handler.
- Throws:
SQLException
- if a database access error occurs
query
public <T> T query(Connection conn,
String sql,
ResultSetHandler<T> rsh)
throws SQLExceptionExecute an SQL SELECT query without any replacement parameters. The caller is responsible for closing the connection.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
conn
- The connection to execute the query in.sql
- The query to execute.rsh
- The handler that converts the results into an object.- Returns:
- The object returned by the handler.
- Throws:
SQLException
- if a database access error occurs
query
@Deprecated
public <T> T query(String sql,
Object param,
ResultSetHandler<T> rsh)
throws SQLExceptionDeprecated. Usequery(String, ResultSetHandler, Object...)
Executes the given SELECT SQL with a single replacement parameter. TheConnection
is retrieved from theDataSource
set in the constructor.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.param
- The replacement parameter.rsh
- The handler used to create the result object from theResultSet
.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs
query
@Deprecated
public <T> T query(String sql,
Object[] params,
ResultSetHandler<T> rsh)
throws SQLExceptionDeprecated. Usequery(String, ResultSetHandler, Object...)
Executes the given SELECT SQL query and returns a result object. TheConnection
is retrieved from theDataSource
set in the constructor.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
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 theResultSet
.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs
query
public <T> T query(String sql,
ResultSetHandler<T> rsh,
Object... params)
throws SQLExceptionExecutes the given SELECT SQL query and returns a result object. TheConnection
is retrieved from theDataSource
set in the constructor.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.rsh
- The handler used to create the result object from theResultSet
.params
- Initialize the PreparedStatement's IN parameters with this array.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs
query
public <T> T query(String sql,
ResultSetHandler<T> rsh)
throws SQLExceptionExecutes the given SELECT SQL without any replacement parameters. TheConnection
is retrieved from theDataSource
set in the constructor.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.rsh
- The handler used to create the result object from theResultSet
.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs
update
public int update(Connection conn,
String sql)
throws SQLExceptionExecute an SQL INSERT, UPDATE, or DELETE query without replacement parameters.- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
update
public int update(Connection conn,
String sql,
Object param)
throws SQLExceptionExecute an SQL INSERT, UPDATE, or DELETE query with a single replacement parameter.- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.param
- The replacement parameter.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
update
public int update(Connection conn,
String sql,
Object... params)
throws SQLExceptionExecute an SQL INSERT, UPDATE, or DELETE query.- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.params
- The query replacement parameters.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
update
public int update(String sql)
throws SQLExceptionExecutes the given INSERT, UPDATE, or DELETE SQL statement without any replacement parameters. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the update will not be saved.- Parameters:
sql
- The SQL statement to execute.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
update
public int update(String sql,
Object param)
throws SQLExceptionExecutes the given INSERT, UPDATE, or DELETE SQL statement with a single replacement parameter. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the update will not be saved.- Parameters:
sql
- The SQL statement to execute.param
- The replacement parameter.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
update
public int update(String sql,
Object... params)
throws SQLExceptionExecutes the given INSERT, UPDATE, or DELETE SQL statement. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the update will not be saved.- Parameters:
sql
- The SQL statement to execute.params
- Initializes the PreparedStatement's IN (i.e. '?') parameters.- Returns:
- The number of rows updated.
- Throws:
SQLException
- if a database access error occurs
insert
public <T> T insert(String sql,
ResultSetHandler<T> rsh)
throws SQLExceptionExecutes the given INSERT SQL without any replacement parameters. TheConnection
is retrieved from theDataSource
set in the constructor.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
insert
public <T> T insert(String sql,
ResultSetHandler<T> rsh,
Object... params)
throws SQLExceptionExecutes the given INSERT SQL statement. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the insert will not be saved.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.params
- Initializes the PreparedStatement's IN (i.e. '?')- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
insert
public <T> T insert(Connection conn,
String sql,
ResultSetHandler<T> rsh)
throws SQLExceptionExecute an SQL INSERT query without replacement parameters.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
insert
public <T> T insert(Connection conn,
String sql,
ResultSetHandler<T> rsh,
Object... params)
throws SQLExceptionExecute an SQL INSERT query.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.params
- The query replacement parameters.- Returns:
- An object generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
insertBatch
public <T> T insertBatch(String sql,
ResultSetHandler<T> rsh,
Object[][] params)
throws SQLExceptionExecutes the given batch of INSERT SQL statements. TheConnection
is retrieved from theDataSource
set in the constructor. ThisConnection
must be in auto-commit mode or the insert will not be saved.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
sql
- The SQL statement to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.params
- Initializes the PreparedStatement's IN (i.e. '?')- Returns:
- The result generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
insertBatch
public <T> T insertBatch(Connection conn,
String sql,
ResultSetHandler<T> rsh,
Object[][] params)
throws SQLExceptionExecutes the given batch of INSERT SQL statements.- Type Parameters:
T
- The type of object that the handler returns- Parameters:
conn
- The connection to use to run the query.sql
- The SQL to execute.rsh
- The handler used to create the result object from theResultSet
of auto-generated keys.params
- The query replacement parameters.- Returns:
- The result generated by the handler.
- Throws:
SQLException
- if a database access error occurs- Since:
- 1.6
QueryRunner的API的更多相关文章
- Java实战之04JavaWeb-06DBUtils
一.DBUtils 1.DBUtils的简介 Commons DbUtils是Apache组织提供的一个对JDBC进行简单封装的开源工具类库,使用它能够简化JDBC应用程序的开发,同时也不会影响程序的 ...
- [JavaWeb]关于DBUtils中QueryRunner的一些解读.
前言:[本文属于原创分享文章, 转载请注明出处, 谢谢.]前面已经有文章说了DBUtils的一些特性, 这里再来详细说下QueryRunner的一些内部实现, 写的有错误的地方还恳请大家指出. Que ...
- c3p0和QueryRunner的结合使用,让开发更加简便
1:DBUtils中的QueryRunner的使用: 1.1:QueryRunner中提供了对SQL语句操作的api: 1.2:主要有三个方法: 1.2.1:query():用于执行select(查询 ...
- QueryRunner类实战
先上一个登录代码---判断登录是否成功 1.c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?&g ...
- Java基础-DButils工具类(QueryRunner)详解
Java基础-DButils工具类(QueryRunner)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 如果只使用JDBC进行开发,我们会发现冗余代码过多,为了简化JDBC ...
- [JavaWeb]关于DBUtils中QueryRunner的一些解读(转)
QueryRunner类 QueryRunner中提供对sql语句操作的API它主要有三个方法 query() 用于执行select update() 用于执行insert/update/delete ...
- pache—DBUtils框架简介、DbUtils类、QueryRunner类 、ResultSetHandler接口
Apache—DBUtils框架简介.DbUtils类.QueryRunner类 .ResultSetHandler接口 commons-dbutils 是 Apache 组织提供的一个开源 JDBC ...
- 【转载】关于DBUtils中QueryRunner的一些解读
前面已经有文章说了DBUtils的一些特性, 这里再来详细说下QueryRunner的一些内部实现, 写的有错误的地方还恳请大家指出. QueryRunner类 QueryRunner中提供对sql语 ...
- 干货来袭-整套完整安全的API接口解决方案
在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...
随机推荐
- UVa 1346 - Songs
题目大意:n张唱片,每张都有长度和频率,要求题目中公式值最小.求一个排序,输出该排序下第m张CD的id. 思路:贪心,长度越长放越后面,频率越低放越后面,所以按len/p去排序即可. #include ...
- safari穿越到chrome
tell application "Safari" set theURL to URL of front document set the clipboard to theURL ...
- ZOJ 1178 Booklet Printing
原题链接 题目大意:书本印刷都是用大开的纸张对折.比如一个册子一共4页,为了方便装订,外侧印刷1.4页,内侧印刷2.3页,这样对折之后就可以按照正常阅读习惯翻页了.此题目的就是给出书的总页数,要求计算 ...
- URIEncoding和useBodyEncodingForURI详解
之前关于编码的问题已经总结过两次了,有些地方写的很粗略.http://blog.itpub.net/29254281/viewspace-775925/http://blog.itpub.net/29 ...
- 作业6 NABCD模型分析,产品Backlog
1.N(Need 需求): 随着生活水平的提高,每个家庭中都会有电脑和移动设备,可以更加快捷方便使用软件.以前孩子练习计算能力需要通做习题卷或老师出题目来进行,但现在只要通过这个四则运算的程序,可以自 ...
- UVa 489 HangmanJudge --- 水题
UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...
- DELPHI WEBSERVICE
一.服务程序 1.依次选择 NEW -> OTHER -> WEB SERVICE -> SOAP SERVER APPLICATION -> ISAPI DYNAMIC LI ...
- HDU-1561 The more, The Better (树形DP+分组背包)
题目大意:给出一片森林,总共有n个点,并且都有权值.从中选出m个,使权值和最大.其中,选某个节点之前必须先选其父节点. 题目分析:给所有的树都加一个共同的权值为0的根节点,使森林变成一棵树.定义状态d ...
- html-javascript前端页面刷新重载的方法汇总
记得我在兴安得力实习要转正的时候,我领导象征性的给我出了一套测试题目,里面就有js闭包和页面刷新等题目.今天把很久之前的测试题目之一,js页面刷新的方法以及页面自动刷新跳转和返回上一页和下一页等方法总 ...
- java 计算器基于工厂模式和功能单一模式
import java.util.Scanner; public class CaculationTest { public static void main(String[] args) { Sca ...