本文整理匯總了Java中org.springframework.jdbc.core.JdbcTemplate.batchUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java JdbcTemplate.batchUpdate方法的具體用法?Java JdbcTemplate.batchUpdate怎麽用?Java JdbcTemplate.batchUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.jdbc.core.JdbcTemplate
的用法示例。
在下文中一共展示了JdbcTemplate.batchUpdate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: cleanAndSetUp
import org.springframework.jdbc.core.JdbcTemplate; //導入方法依賴的package包/類
private void cleanAndSetUp() {
wholeJdbcTemplate.batchUpdate(new String[] {
"Create Table If Not Exists `order` ( `order_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `money` bigint(20) NOT NULL, `create_time` datetime NOT NULL, PRIMARY KEY (`order_id`)) DEFAULT CHARSET=utf8",
"TRUNCATE `order`",
"Create Table If Not Exists `wallet` ( `user_id` int(11) NOT NULL, `total_amount` bigint(20) NOT NULL, `freeze_amount` bigint(20) NOT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8",
"TRUNCATE `wallet`",
"Create Table If Not Exists `accounting` ( `accounting_id` int(11) NOT NULL AUTO_INCREMENT, `p_app_id` varchar(32) NOT NULL, `p_bus_code` varchar(128) NOT NULL, `p_trx_id` varchar(64) NOT NULL, `user_id` int(11) NOT NULL, `amount` bigint(20) NOT NULL, `create_time` datetime NOT NULL, PRIMARY KEY (`accounting_id`)) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8",
"TRUNCATE `accounting`",
"Create Table If Not Exists `point` ( `user_id` int(11) NOT NULL, `point` bigint(20) NOT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8",
"TRUNCATE `point`",
"Create Table If Not Exists `express` ( `p_app_id` varchar(32) NOT NULL, `p_bus_code` varchar(128) NOT NULL, `p_trx_id` varchar(64) NOT NULL, `user_id` int(11) NOT NULL, PRIMARY KEY (`p_app_id`,`p_bus_code`,`p_trx_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8",
"TRUNCATE `express`", "TRUNCATE `executed_trans`", "TRUNCATE `idempotent`",
"INSERT INTO `wallet` (`user_id`, `total_amount`, `freeze_amount`) VALUES ('1', '10000', '0')",
"INSERT INTO `point` (`user_id`, `point`) VALUES ('1', '0')" });
JdbcTemplate transLogJdbcTemplate = new JdbcTemplate(dbForLog.getDataSource());
transLogJdbcTemplate
.batchUpdate(new String[] { "TRUNCATE `trans_log_unfinished`", "TRUNCATE `trans_log_detail`", });
}
示例2: updateObjBatch
import org.springframework.jdbc.core.JdbcTemplate; //導入方法依賴的package包/類
public int[] updateObjBatch(String[] sql) {
//JdbcTemplate jdbcTemplate = (JdbcTemplate) MicroDbHolder.getDbSource(dbName);
JdbcTemplate jdbcTemplate =getMicroJdbcTemplate();
logger.debug(sql);
int[] retStatus=jdbcTemplate.batchUpdate(sql);
return retStatus;
}
示例3: batch
import org.springframework.jdbc.core.JdbcTemplate; //導入方法依賴的package包/類
@Test
public void batch() throws SQLException {
BasicDataSource dataSource = getDataSource(false);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("CREATE TABLE batch (id INTEGER)");
final List<Integer> ids = Arrays.asList(1, 2, 3, 4, 5);
jdbcTemplate.batchUpdate("INSERT INTO batch (id) VALUES (?)",
new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement preparedStatement, int i) throws SQLException {
preparedStatement.setInt(1, ids.get(i));
}
@Override
public int getBatchSize() {
return ids.size();
}
}
);
dataSource.close();
List<MockSpan> spans = mockTracer.finishedSpans();
assertEquals(2, spans.size());
for (MockSpan span : spans) {
assertEquals(Tags.SPAN_KIND_CLIENT, span.tags().get(Tags.SPAN_KIND.getKey()));
assertEquals(JdbcTracingUtils.COMPONENT_NAME, span.tags().get(Tags.COMPONENT.getKey()));
assertThat(span.tags().get(Tags.DB_STATEMENT.getKey()).toString()).isNotEmpty();
assertEquals("h2", span.tags().get(Tags.DB_TYPE.getKey()));
assertEquals("sa", span.tags().get(Tags.DB_USER.getKey()));
assertEquals(0, span.generatedErrors().size());
}
assertNull(mockTracer.activeSpan());
}
示例4: doInTransactionWithoutResult
import org.springframework.jdbc.core.JdbcTemplate; //導入方法依賴的package包/類
@Override
public void doInTransactionWithoutResult(final TransactionStatus status) {
final JdbcTemplate t = new JdbcTemplate(ds);
for (final Block block : blocks) {
final byte[] prevHashBa = block.prevHash.toByteArray();
ArrayUtils.reverse(prevHashBa);
final String putBlockSql = getSql("putBlock");
final byte[] blockIndexBa = block.index.toByteArray();
t.update(putBlockSql, block.hash.toByteArray(), prevHashBa, blockIndexBa, block.toHeaderByteArray());
final String putTransactionSql = getSql("putTransaction");
final String putTransactionInputSql = getSql("putTransactionInput");
final String putTransactionOutputSql = getSql("putTransactionOutput");
final String putTransactionScriptSql = getSql("putTransactionScript");
int transactionIndex = 0;
final List<Object[]> putTransactionList = new ArrayList<>();
final List<Object[]> putTransactionInputList = new ArrayList<>();
final List<Object[]> putTransactionOutputList = new ArrayList<>();
final List<Object[]> putTransactionScriptList = new ArrayList<>();
for (final Transaction transaction : block.getTransactionList()) {
final byte[] txIxByte = new UInt16(transactionIndex).toByteArray();
final byte[] transactionBaseBa = transaction.toBaseByteArray();
add(putTransactionList, blockIndexBa, txIxByte, transaction.hash.toByteArray(), transactionBaseBa);
for (int inputIx = 0; inputIx < transaction.inputs.size(); inputIx++) {
final byte[] txInputIxByte = new UInt32(inputIx).toByteArray();
final CoinReference input = transaction.inputs.get(inputIx);
add(putTransactionInputList, blockIndexBa, txIxByte, txInputIxByte,
input.prevHash.toByteArray(), input.prevIndex.toByteArray());
}
for (int outputIx = 0; outputIx < transaction.outputs.size(); outputIx++) {
final byte[] txOutputIxByte = new UInt16(outputIx).toByteArray();
final TransactionOutput output = transaction.outputs.get(outputIx);
add(putTransactionOutputList, blockIndexBa, txIxByte, txOutputIxByte,
output.assetId.toByteArray(), output.value.toByteArray(),
output.scriptHash.toByteArray());
}
for (int scriptIx = 0; scriptIx < transaction.scripts.size(); scriptIx++) {
final byte[] txScriptIxByte = new UInt32(scriptIx).toByteArray();
final Witness script = transaction.scripts.get(scriptIx);
add(putTransactionScriptList, blockIndexBa, txIxByte, txScriptIxByte,
script.getCopyOfInvocationScript(), script.getCopyOfVerificationScript());
}
transactionIndex++;
}
t.batchUpdate(putTransactionSql, putTransactionList);
t.batchUpdate(putTransactionInputSql, putTransactionInputList);
t.batchUpdate(putTransactionOutputSql, putTransactionOutputList);
t.batchUpdate(putTransactionScriptSql, putTransactionScriptList);
}
}