0

I have an ArrayList of Strings in my code Java, and I need to send this list to my sp in Oracle. I can´t set the list, because Array it's not compatible with ArrayList. How can I send this list?

public static boolean ejecutarPackageSeteado(String procedimiento,ArrayList<String> lista) throws Exception{            
    try{
        cs=getCallableStatement("{call "+procedimiento+"}");
        cs.setArray(1,lista);//THIS LINE SHOW ERROR         
        cs.execute();
    }catch(Exception e){
        System.out.println(e.getMessage());
        throw e;
    }finally{
        cs.close();
        CallableStatementConnection.close();
    }
    return true;
}

This is my PrepareStatement

cs=getCallableStatement("{call "+procedimiento+"}");

//procedimiento is ="INSERTAR.INSERTAR_RUTFORZADA(?)"

private static CallableStatement getCallableStatement(String sql) throws Exception{
        if(CallableStatementConnection==null || CallableStatementConnection.isClosed()){
            CallableStatementConnection = getConnection();
        }
        return CallableStatementConnection.prepareCall(sql);
    }
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Luis Pavez
  • 43
  • 1
  • 2
  • 11

1 Answers1

2

You need to adapt a little from java.util.ArrayList to java.sql.Array

Array sqlArray = connection.createArrayOf("VARCHAR", lista.toArray(new String[0]));
cs.setArray(1,sqlArray );
azro
  • 53,056
  • 7
  • 34
  • 70
  • this does not recognize the word String : "String cannot be resolved to a variable". – Luis Pavez Sep 26 '17 at 13:12
  • @azro now the error is other,in this line "createArrayOf" it says in spanish "Función no soportada", in english its something like "unsupported function". What do you think about this – Luis Pavez Sep 26 '17 at 15:17
  • @LuisPavez what is your SQL statement ? – azro Sep 26 '17 at 16:15