0

I am not getting output when I am directly passing a list through IN clause, but getting output when passing the values separately.

Working Code below:

List<String> resultList = null;
List<String> list = new ArrayList();
list.add("123");
list.add("456"):
String query = "select * from company where id in('123','456')");
 resultList=getJdbcTemplate().queryForList(query, String.class);

Not working code:

List<String> resultList = null;
List<String> list = new ArrayList();
list.add("123");
list.add("456"):
String query = "select * from company where id in(:list)");
resultList=getJdbcTemplate().queryForList(query, String.class);

I want to fetch the query based on the list passed in the query. Could someone help me here

I have created a pojo class Company.java where I have mentioned db column fields. After the query part,

List<Company> comp = getJdbcTemplate().queryForList(query, Company.class);

Error I am getting : Incorrect Column count: expected 1, actual 23

What changes I need to do in above line.

  • 1
    Does this answer your question? [How to execute IN() SQL queries with Spring's JDBCTemplate effectivly?](https://stackoverflow.com/questions/1327074/how-to-execute-in-sql-queries-with-springs-jdbctemplate-effectivly) – Alien Aug 06 '20 at 07:09
  • Yes I got the correct result. But now I am trying to put those fields retrieved from query in a pojo class.. – khaja aminul hussain Aug 06 '20 at 12:44
  • For ex: I have a pojo class Company and I want to store the result of query in pojo.. I tried one method but I am getting error.. please see my edited part above – khaja aminul hussain Aug 06 '20 at 12:45
  • Raise a new question instead. – Alien Aug 06 '20 at 13:56
  • https://stackoverflow.com/q/33008205/6572971 this will help you. – Alien Aug 06 '20 at 13:58

0 Answers0