- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Inserting Array list into HANA database
Try using below code:
Example
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"); // Running a loop over our array of arrays 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()) ; // add comma if this is not the last element if (j < (curr_length - 1)){ arrayFunction = arrayFunction.concat(", ") ; } } arrayFunction = arrayFunction + ")" ; // You can see arrayFunction as it look like below // ARRAY ( ..., .... ,... ) 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;
Output
Output of above program when I run Select statement:
ID Value 0 1 1 1, 2 2 1, 2, 3, 4, 5
Advertisements