栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用JAVA在HANA中插入数组

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用JAVA在HANA中插入数组

@RKR好的,这里有您的示例:

         Integer[][] myarr ={ {1}, {1,2}, {1,2,3,4,5}, {1,2}, {1,2,3} };    String testSection = "Insert Arrays one by one";    stopWatch.start(testSection);    myDBconn.setAutoCommit(false);    Statement stmt = myDBconn.createStatement();    stmt = myDBconn.createStatement();    stmt.execute("TRUNCATE TABLE DEVDUDE.T3");    // loop over our array of arrays and visit each once    for (int i = 0 ; i < (myarr.length); i++) {        int curr_length = myarr[i].length;        String arrayFunction = "ARRAY (";        for (int j = 0; j < (curr_length); j++){ arrayFunction = arrayFunction.concat(myarr[i][j].toString()) ; // add comma if this is not the last element if (j < (curr_length - 1)){     arrayFunction = arrayFunction.concat(", ") ; }        }        arrayFunction = arrayFunction + ")" ;        // now the arrayFunction should loook like this        // ARRAY ( ..., .... ,... )        String insCMD = "INSERT INTO T3 (id, c1) "  + " 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;

不,这个代码并 不能 净化输入到INSERT语句,但有以待进行,以避免SQL注入。

当我运行代码时,将输出以下内容:

INSERT INTO T3 (id, c1)  VALUES (0, ARRAY (1) ) Loop round 0, last affected row count 1INSERT INTO T3 (id, c1)  VALUES (1, ARRAY (1, 2) ) Loop round 1, last affected row count 1INSERT INTO T3 (id, c1)  VALUES (2, ARRAY (1, 2, 3, 4, 5) ) Loop round 2, last affected row count 1INSERT INTO T3 (id, c1)  VALUES (3, ARRAY (1, 2) ) Loop round 3, last affected row count 1INSERT INTO T3 (id, c1)  VALUES (4, ARRAY (1, 2, 3) ) Loop round 4, last affected row count 1

并在表上的SELECT返回:

ID  C10   1 1   1, 2         2   1, 2, 3, 4, 53   1, 2         4   1, 2, 3


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/446845.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号