@Override public T call() throws Exception { return queryRunner.insertBatch(conn, sql, rsh, params); } });
@Override public T call() throws Exception { return queryRunner.insertBatch(sql, rsh, params); } });
/** * 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); }
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; }
/** * 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); }
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); } }
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); } }
@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); } }); }
params[1][1] = "Blah2"; List<Object> generatedKeys = runner.insertBatch("INSERT INTO blah(col1, col2) VALUES(?,?)", handler, params);
@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); } }); }