static String updateQueryWithArrayParameters ( String parsedQuery , List < ArrayParameter > arrayParametersSortedAsc ) { if ( arrayParametersSortedAsc . isEmpty ( ) ) { return parsedQuery ; } StringBuilder sb = new StringBuilder ( ) ; Iterator < ArrayParameter > parameterToReplaceIt = arrayParametersSortedAsc . iterator ( ) ; ArrayParameter nextParameterToReplace = parameterToReplaceIt . next ( ) ; // PreparedStatement index starts at 1 int currentIndex = 1 ; for ( char c : parsedQuery . toCharArray ( ) ) { if ( nextParameterToReplace != null && c == ' ' ) { if ( currentIndex == nextParameterToReplace . parameterIndex ) { sb . append ( "?" ) ; for ( int i = 1 ; i < nextParameterToReplace . parameterCount ; i ++ ) { sb . append ( ",?" ) ; } if ( parameterToReplaceIt . hasNext ( ) ) { nextParameterToReplace = parameterToReplaceIt . next ( ) ; } else { nextParameterToReplace = null ; } } else { sb . append ( c ) ; } currentIndex ++ ; } else { sb . append ( c ) ; } } return sb . toString ( ) ; }
Change the query to replace ? at each arrayParametersSortedAsc . parameterIndex with ? ? ? .. multiple arrayParametersSortedAsc . parameterCount