I want to insert a set of arrays into a database(HANA) in a loop.My code is below:
public class jdemo {
public static void main(String[] args) {
Connect
The topic of "ARRAY inserts into HANA" has been discussed a couple of times here on SO already. HANA only supports to store arrays via the ARRAY() function. This function does not take a list as the parameter, but only separate elements.
So, instead of
String sql="INSERT INTO TABLE1 VALUES(1,ARRAY(?))"
you would have to write
String sql="INSERT INTO TABLE1 VALUES(1, ARRAY( 1, 2, 3))"
For the JDBC driver: HANA JDBC doesn't automatically handle JAVA arrays to HANA arrays - that's something the developer will have to do manually. (yes, it's not nice, I know).
In short: currently (HANA 1.0 SP12) arrays can basically be used internally (within a stored procedure), but they are not first-class-citizen data types. (<- that's my opinion!)
You are using createStatement instead of prepareStatement. createStatement does nut support parameters!
Check https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html
And https://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html
for details Hope this helps
Would be nice if you provide DDL, error messages etc. next time, then its easier to analyze.
Just an idea:
Instead of storing an array in your column, you can save a string separated by colons. When you query the data from your database, you can use split(","), and you automatically have your array that you need (after Integer.parseInt(String))