Example usage for org.apache.commons.dbutils QueryRunner query

List of usage examples for org.apache.commons.dbutils QueryRunner query

Introduction

In this page you can find the example usage for org.apache.commons.dbutils QueryRunner query.

Prototype

public <T> T query(Connection conn, String sql, ResultSetHandler<T> rsh, Object... params) throws SQLException 

Source Link

Document

Execute an SQL SELECT query with replacement parameters.

Usage

From source file:it.attocchi.db.DbUtilsConnector.java

public <T> T executeSingle(boolean keepConnOpen, String aQuery, Class<T> clazz, Object... params)
        throws Exception {
    T result = null;/*from ww w .  ja  v  a2s . c o  m*/

    // No DataSource so we must handle Connections manually
    QueryRunner run = new QueryRunner();

    try {

        logger.debug(aQuery);
        result = run.query(getConnection(), aQuery, getResultSetHandlerSingle(clazz), params);
    } catch (Exception ex) {
        logger.error("Error executeSingle", ex);
    } finally {
        if (!keepConnOpen)
            close();
    }

    return result;
}

From source file:framework.retrieval.engine.index.all.database.impl.rdAbstract.DefaultRDatabaseIndexAllImpl.java

/**
 * ?SQL??/*ww  w.ja v a 2s  .  c  o m*/
 * @param limitSql         SQL
 * @param params         SQL?
 * @return
 */
@SuppressWarnings("unchecked")
public List<Map> getResult(String limitSql, Object[] params) {
    Connection conn = getConnection();

    QueryRunner qRunner = new QueryRunner();
    ResultSetHandler rsh = new MapListHandler();
    List<Map> result = null;

    try {
        if (params != null && params.length > 0) {
            result = (List<Map>) qRunner.query(conn, limitSql, rsh, params);
        } else {
            result = (List<Map>) qRunner.query(conn, limitSql, rsh);
        }
    } catch (SQLException e) {
        throw new RetrievalIndexException(e);
    } finally {
        close(conn);
    }

    return result;
}

From source file:com.softberries.klerk.dao.DocumentItemDao.java

public DocumentItem find(Long id, QueryRunner run, Connection conn) throws SQLException {
    DocumentItem p = null;/*from  www . j  av  a  2 s.com*/
    ResultSetHandler<DocumentItem> h = new BeanHandler<DocumentItem>(DocumentItem.class);
    p = run.query(conn, SQL_FIND_DOCUMENTITEM_BY_ID, h, id);
    ProductDao pdao = new ProductDao(this.path);
    p.setProduct(pdao.find(p.getProduct_id(), run, conn));
    return p;
}

From source file:com.pinterest.deployservice.db.DBBuildDAOImpl.java

@Override
public BuildBean getLatest(String buildName, String branch) throws Exception {
    QueryRunner run = new QueryRunner(this.dataSource);
    ResultSetHandler<BuildBean> h = new BeanHandler<>(BuildBean.class);
    if (StringUtils.isNotEmpty(branch)) {
        return run.query(GET_LATEST_BUILD_BY_NAME_2, h, buildName, branch);
    } else {// ww w  .  ja  v a 2 s  .c  om
        return run.query(GET_LATEST_BUILD_BY_NAME, h, buildName);
    }
}

From source file:com.softberries.klerk.dao.AddressDao.java

public List<Address> findAllByCompanyId(Long companyId, QueryRunner run, Connection conn) throws SQLException {
    List<Address> addresses = new ArrayList<Address>();
    ResultSetHandler<List<Address>> h = new BeanListHandler<Address>(Address.class);
    addresses = run.query(conn, SQL_FIND_ADDRESS_ALL_BY_COMPANY_ID, h, companyId);
    return addresses;
}

From source file:com.softberries.klerk.dao.AddressDao.java

public List<Address> findAllByPersonId(Long companyId, QueryRunner run, Connection conn) throws SQLException {
    List<Address> addresses = new ArrayList<Address>();
    ResultSetHandler<List<Address>> h = new BeanListHandler<Address>(Address.class);
    addresses = run.query(conn, SQL_FIND_ADDRESS_ALL_BY_PERSON_ID, h, companyId);
    return addresses;
}

From source file:hermes.store.schema.DefaultJDBCAdapter.java

public int getDepth(Connection connection, String storeId, Destination destination)
        throws SQLException, JMSException {
    final QueryRunner runner = new QueryRunner();

    return (Integer) runner.query(connection, statements.getDepthStatement(),
            new Object[] { storeId, JMSUtils.getDestinationName(destination) }, new ResultSetHandler() {
                public Object handle(ResultSet rs) throws SQLException {
                    rs.next();//from  w w  w .j a  v a 2 s .  co m

                    return rs.getInt(1);
                }
            });
}

From source file:com.softberries.klerk.dao.ProductDao.java

public Product find(Long id, QueryRunner run1, Connection conn1) throws SQLException {
    Product p = null;/*  ww  w  . j  av a 2 s . co  m*/
    try {
        init();
        ResultSetHandler<Product> h = new BeanHandler<Product>(Product.class);
        p = run1.query(conn1, SQL_FIND_PRODUCT_BY_ID, h, id);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    return p;
}

From source file:com.softberries.klerk.dao.DocumentItemDao.java

public List<DocumentItem> findAllByDocumentId(Long docId, QueryRunner run, Connection conn)
        throws SQLException {
    List<DocumentItem> items = new ArrayList<DocumentItem>();
    ResultSetHandler<List<DocumentItem>> h = new BeanListHandler<DocumentItem>(DocumentItem.class);
    items = run.query(conn, SQL_FIND_DOCUMENTITEM_ALL_BY_DOCUMENT_ID, h, docId);
    ProductDao pdao = new ProductDao(this.path);
    for (DocumentItem di : items) {
        di.setProduct(pdao.find(di.getProduct_id(), run, conn));
    }//from   w  ww. ja  v a 2s  .  c o m
    return items;
}

From source file:com.softberries.klerk.dao.PeopleDao.java

/**
 * Used by other DAO's, reuses existing connection, runner and result set
 * objects//from  w w w  .  jav  a2 s .  c  o m
 * 
 * @param id
 * @param run
 * @param conn
 * @param st
 * @param generatedKeys
 * @return
 * @throws SQLException
 */
public Person find(Long id, QueryRunner run, Connection conn, PreparedStatement st, ResultSet generatedKeys)
        throws SQLException {
    Person p = null;
    ResultSetHandler<Person> h = new BeanHandler<Person>(Person.class);
    p = run.query(conn, SQL_FIND_PERSON_BY_ID, h, id);
    if (p != null) {
        // find addresses
        AddressDao adrDao = new AddressDao();
        p.setAddresses(adrDao.findAllByPersonId(p.getId(), run, conn));
    }
    return p;
}