将数组列表插入HANA数据库
尝试使用以下代码:
示例
Integer[][] myarray ={ {1}, {1,2}, {1,2,3,4,5} };
String test = "Insert Arrays";
stopWatch.start(test);
myDBconn.setAutoCommit(false);
Statement stmt = myDBconn.createStatement();
stmt = myDBconn.createStatement();
stmt.execute("TRUNCATE TABLE Schema.Table1");
//在我们的数组数组上运行循环
for (int i = 0 ; i < (myarray.length); i++) {
int curr_length = myarray[i].length;
String arrayFunction = "ARRAY (";
for (int j = 0; j < (curr_length); j++){
arrayFunction = arrayFunction.concat(myarr[i][j].toString()) ;
//如果不是最后一个元素,请添加逗号
if (j < (curr_length - 1)){
arrayFunction = arrayFunction.concat(", ") ;
}
}
arrayFunction = arrayFunction + ")" ;
//您可以看到arrayFunction,如下所示
//数组(...,....,,)
String insCMD = "INSERT INTO Table1 (id, Value) "
+ " VALUES (" + i + ", "
+ arrayFunction
+ " ) ";
System.out.println(insCMD);
int affectedRows = stmt.executeUpdate(insCMD);
System.out.println("Loop round " + i
+ ", last affected row count " + affectedRows);
}
myDBconn.commit();
stmt.close();
stmt = null;输出结果
运行Select语句时上述程序的输出:
ID Value 0 1 1 1, 2 2 1, 2, 3, 4, 5
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练