是否可以在HANA中批量插入? [英] Is it possible bulk insert in HANA?
问题描述
我想批量插入花名.目前我正在使用Java从结果集中逐行插入.是否可以同时插入多行?有可能吗? (我不想只导入大容量插入内容)我到处搜索,找不到任何好的答案.有什么帮助吗?
I want to insert into hana by bulk.Currently I am using Java to insert line by line from the result set.Is there a way to insert multiple rows at a time? Is it possible to do? (I do not want import only bulk insert) I searched all over and could not find any good answer.Any help is appreciated?
推荐答案
对于JAVA/JDBC代码,存在所谓的批处理接口. 这是我用于测试的一个旧示例:
For JAVA/JDBC code, there exists the so-called batch interface. Here's an old example that I used for testing:
myDBconn.setAutoCommit(false);
PreparedStatement insStmt = myDBconn
.prepareStatement("INSERT INTO EFASHION.SHOP_FACTS_INS_DEMO VALUES"
+ " (?, ?, ?, ?, ?, ?, ?, ? )");
for (int i = 1; i <= LOOPCNT; i++) {
myfacts.createNewFact(); // create a JAVA object with new data
// prepare the new data for the batch
// note that this is a typed assignment.
insStmt.setInt(1, i);
insStmt.setInt(2, myfacts.article_id);
insStmt.setInt(3, myfacts.color_code);
insStmt.setInt(4, myfacts.week_id);
insStmt.setInt(5, myfacts.shop_id);
insStmt.setDouble(6, myfacts.margin);
insStmt.setDouble(7, myfacts.amount_sold);
insStmt.setInt(8, myfacts.quantity_sold);
// add the new data to the batch
insStmt.addBatch();
// limit the batch size, to prevent client side out of memory errors.
// but DON'T commit yet!
// Remember the data in the current batch is kept in client
// memory as long as we don't send it to the HANA server
if (i % BATCHSIZE == 0) {
// executeBatch returns the number of affected rows.
// if we want to use this in the application we just keep adding this up
affectedRows += insStmt.executeBatch();
}
}
// the final batch execution for whatever remained in the
// last batch
affectedRows += insStmt.executeBatch();
// finally commit
myDBconn.commit();
JDBC文档中记录了所有内容,因此遵循它应该不是问题.
All that is documented in the JDBC docu so it shouldn't be a problem to follow this.
备注:不支持ARRAY数据类型(既不针对单个预准备语句也不针对批处理),以防万一,这就是您想要做的...
Remark: ARRAY data types are not supported (neither for single prepared statements nor for batches) - just in case that is what you wanted to do...
这篇关于是否可以在HANA中批量插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!