org.apache.commons.dbutils

Class QueryRunner

    • Constructor Detail

      • QueryRunner

        public QueryRunner()
        Constructor for QueryRunner.
      • QueryRunner

        public QueryRunner(boolean pmdKnownBroken)
        Constructor for QueryRunner that controls the use of ParameterMetaData.
        Parameters:
        pmdKnownBroken - Some drivers don't support ParameterMetaData.getParameterType(int); if pmdKnownBroken 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 a DataSource to use. Methods that do not take a Connection parameter will retrieve connections from this DataSource.
        Parameters:
        ds - The DataSource to retrieve connections from.
      • QueryRunner

        public QueryRunner(DataSource ds,
        boolean pmdKnownBroken)
        Constructor for QueryRunner that takes a DataSource and controls the use of ParameterMetaData. Methods that do not take a Connection parameter will retrieve connections from this DataSource.
        Parameters:
        ds - The DataSource to retrieve connections from.
        pmdKnownBroken - Some drivers don't support ParameterMetaData.getParameterType(int); if pmdKnownBroken 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 SQLException
        Execute 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 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.
        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 SQLException
        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 SQLException
        Execute 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 SQLException
        Execute 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 SQLException
        Execute 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 SQLException
        Executes the given SELECT SQL with a single replacement parameter. The Connection is retrieved from the DataSource 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 the ResultSet.
        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 SQLException
        Executes the given SELECT SQL query and returns a result object. The Connection is retrieved from the DataSource 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 the ResultSet.
        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 SQLException
        Executes the given SELECT SQL query and returns a result object. The Connection is retrieved from the DataSource 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 the ResultSet.
        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 SQLException
        Executes the given SELECT SQL without any replacement parameters. The Connection is retrieved from the DataSource 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 the ResultSet.
        Returns:
        An object generated by the handler.
        Throws:
        SQLException - if a database access error occurs
      • update

        public int update(Connection conn,
        String sql)
        throws SQLException
        Execute 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 SQLException
        Execute 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 SQLException
        Execute 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 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.
        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 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.
        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 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.
        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 SQLException
        Executes the given INSERT SQL without any replacement parameters. The Connection is retrieved from the DataSource 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 the ResultSet 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 SQLException
        Executes the given INSERT SQL statement. The Connection is retrieved from the DataSource set in the constructor. This Connection 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 the ResultSet 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 SQLException
        Execute 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 the ResultSet 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 SQLException
        Execute 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 the ResultSet 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 SQLException
        Executes the given batch of INSERT SQL statements. The Connection is retrieved from the DataSource set in the constructor. This Connection 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 the ResultSet 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 SQLException
        Executes 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 the ResultSet 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的更多相关文章

  1. Java实战之04JavaWeb-06DBUtils

    一.DBUtils 1.DBUtils的简介 Commons DbUtils是Apache组织提供的一个对JDBC进行简单封装的开源工具类库,使用它能够简化JDBC应用程序的开发,同时也不会影响程序的 ...

  2. [JavaWeb]关于DBUtils中QueryRunner的一些解读.

    前言:[本文属于原创分享文章, 转载请注明出处, 谢谢.]前面已经有文章说了DBUtils的一些特性, 这里再来详细说下QueryRunner的一些内部实现, 写的有错误的地方还恳请大家指出. Que ...

  3. c3p0和QueryRunner的结合使用,让开发更加简便

    1:DBUtils中的QueryRunner的使用: 1.1:QueryRunner中提供了对SQL语句操作的api: 1.2:主要有三个方法: 1.2.1:query():用于执行select(查询 ...

  4. QueryRunner类实战

    先上一个登录代码---判断登录是否成功 1.c3p0-config.xml <?xml version="1.0" encoding="UTF-8"?&g ...

  5. Java基础-DButils工具类(QueryRunner)详解

    Java基础-DButils工具类(QueryRunner)详解 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 如果只使用JDBC进行开发,我们会发现冗余代码过多,为了简化JDBC ...

  6. [JavaWeb]关于DBUtils中QueryRunner的一些解读(转)

    QueryRunner类 QueryRunner中提供对sql语句操作的API它主要有三个方法 query() 用于执行select update() 用于执行insert/update/delete ...

  7. pache—DBUtils框架简介、DbUtils类、QueryRunner类 、ResultSetHandler接口

    Apache—DBUtils框架简介.DbUtils类.QueryRunner类 .ResultSetHandler接口 commons-dbutils 是 Apache 组织提供的一个开源 JDBC ...

  8. 【转载】关于DBUtils中QueryRunner的一些解读

    前面已经有文章说了DBUtils的一些特性, 这里再来详细说下QueryRunner的一些内部实现, 写的有错误的地方还恳请大家指出. QueryRunner类 QueryRunner中提供对sql语 ...

  9. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

随机推荐

  1. 240. Search a 2D Matrix II

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  2. 图像处理之image stitching

    背景介绍 图像拼接是一项应用广泛的图像处理技术.根据特征点的相互匹配,可以将多张小视角的图像拼接成为一张大视角的图像,在广角照片合成.卫星照片处理.医学图像处理等领域都有应用.早期的图像拼接主要是运用 ...

  3. ZOJ 1101 Gamblers

    原题链接 题目大意:一群人聚众赌博.每个人先分别押注不同的金额,可以相互借钱.开奖之后,如果某个人的押注的金额正好等于任何其他三个人金额总和,那这个人就赢得其他三个人的赌注.如果同时有两个以上的赢家, ...

  4. iPhone 上拨号键盘的发音规律

    上个学期在信号处理课上选做的题目和这个问题正好相关. 如焕杰同学所说,iPhone拨号音是使用双音多频信号(DTMF).双音多频信号是贝尔实验室发明的,通常用于发送被叫号码,它取代了早起的脉冲拨号方法 ...

  5. linux 网络协议分析---3

    本章节主要介绍linxu网络模型.以及常用的网络协议分析以太网协议.IP协议.TCP协议.UDP协议 一.网络模型 TCP/IP分层模型的四个协议层分别完成以下的功能: 第一层 网络接口层 网络接口层 ...

  6. [转] shiro简单配置

    shiro(1) 注:这里只介绍spring配置模式. 因为官方例子虽然中有更加简洁的ini配置形式,但是使用ini配置无法与spring整合.而且两种配置方法一样,只是格式不一样. 涉及的jar包 ...

  7. java编程acm基础

    java还是不错的昂! import java.util.*; import java.io.*; public class text{ static int a=100; public static ...

  8. iOS的一些坑

    1.动态绑定元素,不能绑定到body上 $(document).on('click','#nuse-content .coupon',fn) 这样是不行的,会导致事件无法触发,除非给要绑定时间的元素显 ...

  9. web前端学习策略

  10. urllib,urllib2,requests对比

    #coding:utf-8 import urllib2 import urllib import httplib import socket import requests #实现以下几个方面内容: ...