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

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

Introduction

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

Prototype

public int[] batch(String sql, Object[][] params) throws SQLException 

Source Link

Document

Execute a batch of SQL INSERT, UPDATE, or DELETE queries.

Usage

From source file:com.fluke.database.dataservice.IntraDayDao.java

public void insertBatch(String id, List<IntradayTicker> tickers) {
    QueryRunner runner = new QueryRunner(DatabaseProperty.getDataSource());
    Object params[][] = new Object[tickers.size()][7];
    int count = 0;
    for (IntradayTicker ticker : tickers) {
        params[count] = new Object[7];
        params[count][0] = id;/*from  www .  ja v a2s  .c  o  m*/
        params[count][1] = ticker.getOpenPrice();
        params[count][2] = ticker.getClosePrice();
        params[count][3] = ticker.getHighPrice();
        params[count][4] = ticker.getLowPrice();
        params[count][5] = ticker.getVolume();
        params[count][6] = ticker.getTime();
        count++;
    }
    try {
        runner.batch(sql, params);
    } catch (SQLException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:org.rti.zcore.dar.utils.DatabaseUtils.java

/**
 * for batch updates/*from   w w  w.  j a va 2  s . c om*/
 * unused
 *
 * @param sql
 * @param params
 * @return
 * @throws Exception
 */
public static int[] update(java.lang.String sql, java.lang.Object[][] params) throws java.lang.Exception {
    DataSource dataSource = null;
    dataSource = DatabaseUtils.getZEPRSDataSource();
    QueryRunner run = new QueryRunner(dataSource);
    int[] result = run.batch(sql, params);
    return result;
}

From source file:ttf.persistence.sql.FeatureSaver.java

private void insertFeatures(QueryRunner run, String table, String fieldName, String id, String type,
        PropertyGroup<String, NumericalValue> group) throws SQLException {
    Object[][] rows = new Object[group.size()][];

    int i = 0;/*from  ww w .  j av a 2s.  com*/
    for (Entry<String, NumericalValue> entry : group.entrySet()) {
        Object[] row = { //
                type, //
                entry.getKey(), //
                entry.getValue().getDouble(), //
                id };
        rows[i++] = row;
    }

    String sql = "INSERT INTO " + table + " (type, name, score, " + fieldName + ") " + "VALUES (?, ?, ?, ?)";
    run.batch(sql, rows);
}