org.apache.commons.dbutils.QueryRunner.insertBatch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.2k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.apache.commons.dbutils.QueryRunner.insertBatch方法的一些代码示例,展示了QueryRunner.insertBatch的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryRunner.insertBatch方法的具体详情如下:
包路径:org.apache.commons.dbutils.QueryRunner
类名称:QueryRunner
方法名:insertBatch

QueryRunner.insertBatch介绍

[英]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.
[中]执行给定的一批INSERT SQL语句。Connection是从构造函数中的DataSource集合中检索的。此Connection必须处于自动提交模式,否则插入内容将无法保存。

代码示例

代码示例来源:origin: commons-dbutils/commons-dbutils

@Override
  public T call() throws Exception {
    return queryRunner.insertBatch(conn, sql, rsh, params);
  }
});

代码示例来源:origin: commons-dbutils/commons-dbutils

@Override
  public T call() throws Exception {
    return queryRunner.insertBatch(sql, rsh, params);
  }
});

代码示例来源:origin: commons-dbutils/commons-dbutils

/**
 * Executes the given batch of INSERT SQL statements.
 * @param <T> The type of object that the handler returns
 * @param conn The connection to use to run the query.
 * @param sql The SQL to execute.
 * @param rsh The handler used to create the result object from
 * the <code>ResultSet</code> of auto-generated keys.
 * @param params The query replacement parameters.
 * @return The result generated by the handler.
 * @throws SQLException if a database access error occurs
 * @since 1.6
 */
public <T> T insertBatch(Connection conn, String sql, ResultSetHandler<T> rsh, Object[][] params) throws SQLException {
  return insertBatch(conn, false, sql, rsh, params);
}

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

public static <T> T insertBatch(String sql, ResultSetHandler<T> resultSetHandler, Object[][] params) {
  T result = null;
  synchronized (queryRunner) {
    try {
      result = queryRunner.insertBatch(connection, sql, resultSetHandler, params);
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  return result;
}

代码示例来源:origin: commons-dbutils/commons-dbutils

/**
 * Executes the given batch of INSERT SQL statements. The
 * <code>Connection</code> is retrieved from the <code>DataSource</code>
 * set in the constructor.  This <code>Connection</code> must be in
 * auto-commit mode or the insert will not be saved.
 * @param <T> The type of object that the handler returns
 * @param sql The SQL statement to execute.
 * @param rsh The handler used to create the result object from
 * the <code>ResultSet</code> of auto-generated keys.
 * @param params Initializes the PreparedStatement's IN (i.e. '?')
 * @return The result generated by the handler.
 * @throws SQLException if a database access error occurs
 * @since 1.6
 */
public <T> T insertBatch(String sql, ResultSetHandler<T> rsh, Object[][] params) throws SQLException {
  return insertBatch(this.prepareConnection(), true, sql, rsh, params);
}

代码示例来源:origin: hypercube1024/firefly

public <T, R> R insertObjectBatch(Connection connection, ResultSetHandler<R> rsh, Class<T> t, List<T> list) {
  SQLMapper sqlMapper = defaultBeanProcessor.generateInsertSQL(t);
  Assert.notNull(sqlMapper, "the sql mapper must not be null");
  Assert.notEmpty(sqlMapper.propertyMap, "the property map must not be empty");
  Object[][] params = new Object[list.size()][sqlMapper.propertyMap.size()];
  for (int i = 0; i < list.size(); i++) {
    Object object = list.get(i);
    final int j = i;
    sqlMapper.propertyMap.forEach((property, index) -> {
      try {
        params[j][index] = ReflectUtils.get(object, property);
      } catch (Throwable ignored) {
      }
    });
  }
  try {
    return getRunner().insertBatch(connection, sqlMapper.sql, rsh, params);
  } catch (SQLException e) {
    log.error("insert batch exception", e);
    throw new DBException(e);
  }
}

代码示例来源:origin: com.fireflysource/firefly-db

public <T, R> R insertObjectBatch(Connection connection, ResultSetHandler<R> rsh, Class<T> t, List<T> list) {
  SQLMapper sqlMapper = defaultBeanProcessor.generateInsertSQL(t);
  Assert.notNull(sqlMapper, "the sql mapper must not be null");
  Assert.notEmpty(sqlMapper.propertyMap, "the property map must not be empty");
  Object[][] params = new Object[list.size()][sqlMapper.propertyMap.size()];
  for (int i = 0; i < list.size(); i++) {
    Object object = list.get(i);
    final int j = i;
    sqlMapper.propertyMap.forEach((property, index) -> {
      try {
        params[j][index] = ReflectUtils.get(object, property);
      } catch (Throwable ignored) {
      }
    });
  }
  try {
    return getRunner().insertBatch(connection, sqlMapper.sql, rsh, params);
  } catch (SQLException e) {
    log.error("insert batch exception", e);
    throw new DBException(e);
  }
}

代码示例来源:origin: hypercube1024/firefly

@Override
public <R> CompletableFuture<R> insertBatch(String sql, Object[][] params, Func1<SQLResultSet, R> handler) {
  return jdbcHelper.async(connection, (conn, helper) -> {
    try {
      return helper.getRunner().insertBatch(connection, sql, rs -> handler.call(new JDBCResultSet(rs)), params);
    } catch (SQLException e) {
      throw new DBException(e);
    }
  });
}

代码示例来源:origin: commons-dbutils/commons-dbutils

params[1][1] = "Blah2";
List<Object> generatedKeys = runner.insertBatch("INSERT INTO blah(col1, col2) VALUES(?,?)", handler, params);

代码示例来源:origin: com.fireflysource/firefly-db

@Override
public <R> CompletableFuture<R> insertBatch(String sql, Object[][] params, Func1<SQLResultSet, R> handler) {
  return jdbcHelper.async(connection, (conn, helper) -> {
    try {
      return helper.getRunner().insertBatch(connection, sql, rs -> handler.call(new JDBCResultSet(rs)), params);
    } catch (SQLException e) {
      throw new DBException(e);
    }
  });
}

相关文章