java - What SQL Parameter Type to use for an IN condition when using MappingSqlQuery -
i having trouble declaring parameter in condition when use mappingsqlquery feature of spring jdbc. using oracle database.
i have tried use integer
, array
without result.
import org.springframework.beans.factory.annotation.autowired; import org.springframework.jdbc.core.sqlparameter; import org.springframework.jdbc.object.mappingsqlquery; import org.springframework.stereotype.component; import javax.sql.datasource; import java.sql.resultset; import java.sql.sqlexception; import java.sql.types; import java.util.list; @component public class testquery extends mappingsqlquery<list<object>> { @autowired public testquery(datasource ds) { super(ds, "select test_id, name test_table test_id in (?)"); ///////////////////////////////// // sql type declare here? declareparameter(new sqlparameter(types.)); ///////////////////////////////// compile(); } @override protected list<object> maprow(resultset rs, int i) throws sqlexception { // ... return null; } }
i want use object of testquery class follows:
... @autowired private testquery testquery; public list<object> ...() { list<integer> ids = arrays.aslist(36006122, 36004367); list<object> objects = testquery.findobject(ids); return objects; } ...
the information can find here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/jdbc.html#jdbc-in-clause problem not declaring parameter there, while needed in order use mappingsqlquery
feature: org.springframework.dao.invaliddataaccessapiusageexception: 1 parameters supplied, 0 parameters declared in class
database type: oracle
spring version: 3.2.14.release
oracle dependency version: ojdbc7:12.1.0.1
edit: added testquery usage
in meantime have fixed abandoning mappingsqlquery
, pretty using this: https://stackoverflow.com/a/1327222/1019778 in combination namedparameterjdbctemplate
.
type int
should work here. also, if want pass in list
of values, can this:
where some_column_name in (:lst)
.
should pass in actual values:
query.setparameterlist("lst", somejavalistofvalues);
Comments
Post a Comment