How to insert an array in a loop to the database

前端 未结 3 1858
小蘑菇
小蘑菇 2021-01-25 03:10

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         


        
相关标签:
3条回答
  • 2021-01-25 03:55

    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!)

    0 讨论(0)
  • 2021-01-25 03:55

    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.

    0 讨论(0)
  • 2021-01-25 04:05

    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))

    0 讨论(0)
提交回复
热议问题