我想通過批量插入到hana中。目前我使用Java從結果集中逐行插入。是否有一種方法可以一次插入多行?有可能嗎? (我不想只進口批量插入)我搜遍了,找不到任何好的答案。任何幫助表示讚賞?可以批量插入HANA嗎?
回答
對於JAVA/JDBC代碼,存在所謂的批處理接口。 下面是我用於測試的老例子:
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實況文件記錄,以便它不應該是遵循這一問題。
備註:ARRAY數據類型不支持(無論單準備好的發言,也不是批) - 只是這是你想要做什麼情況下...
@ Lars.Br然後如何在HANA中上傳數組?我查詢並獲取結果集中的數組,但如何將它插入到HANA,因爲'insStmt.setArray(9,myArray);'在我的插入片段看起來像llike時無效'INSERT INTO EFASHION.SHOP_FACTS_INS_DEMO VALUES「 +」 (?,?,?,?,?,?,?,?,?,ARRAY(?))「);'但是當我手動插入像'INSERT INTO EFASHION.SHOP_FACTS_INS_DEMO VALUES」 + ,?,?,?,?,?,ARRAY(1,2,3))「);'工作正常。 – RKR
請檢查現有的討論:http://stackoverflow.com/questions/40102034/import-array-type-into-hana/40378906#40378906和http://stackoverflow.com/questions/41338263/upload-an -array-in-hana/41353326#41353326 –
另外:你要求BULK數據加載,而不是ARRAY插入。請在這樣的特定級別上進行詢問時,請務必使用正確的術語。謝謝。 –
請上正是你想做的事更具體,例如您想要使用哪種語言或工具。 HANA確實支持批量數據加載 - 這一切都取決於您想要使用的內容。 –
我使用java從結果集中插入數據。但是如果我逐行插入它會消耗更多時間。是否有一種方法可以批量插入? (一次插入多行) – RKR