java - How set Array/List in Spring jdbcTemplate as parameter? -


i have sql query many placeholders '?', builds dynamically, want put array of values replace placeholders. size of array can different every time. array consists parameters in order.

return jdbctemplate.query(queries.somequery,     new object[] {/* array must here */},     new resultsetextractor<list<string>>() {         @override         public list<string> extractdata(resultset resultset)          }     }); 

example of sql generations:

for (int j = 0; j < y; j++) {         conditionsbuilder.append("\n , p"+i+".object_id=o.object_id\n" +                 "    , p"+i+".attr_id =?\n" +                 "    , p"+i+".value =?\n");         tablesbuilder.append(",patameters p"+i+" ");         i++;     } 

use arraylist:

arraylist<object> values = new arraylist<>; 

in for loop should add values in order appear in query:

values.add(value); 

then turn array:

return jdbctemplate.query(query, values.toarray(), resultsetextractor); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -