2017-01-16 53 views
0

我想通过批量插入到hana中。目前我使用Java从结果集中逐行插入。是否有一种方法可以一次插入多行?有可能吗? (我不想只进口批量插入)我搜遍了,找不到任何好的答案。任何帮助表示赞赏?可以批量插入HANA吗?

+0

请上正是你想做的事更具体,例如您想要使用哪种语言或工具。 HANA确实支持批量数据加载 - 这一切都取决于您想要使用的内容。 –

+0

我使用java从结果集中插入数据。但是如果我逐行插入它会消耗更多时间。是否有一种方法可以批量插入? (一次插入多行) – RKR

回答

1

对于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数据类型不支持(无论单准备好的发言,也不是批) - 只是这是你想要做什么情况下...

+0

@ 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

+0

请检查现有的讨论:http://stackoverflow.com/questions/40102034/import-array-type-in​​to-hana/40378906#40378906和http://stackoverflow.com/questions/41338263/upload-an -array-in-hana/41353326#41353326 –

+0

另外:你要求BULK数据加载,而不是ARRAY插入。请在这样的特定级别上进行询问时,请务必使用正确的术语。谢谢。 –