Announcement Announcement Module
Collapse
No announcement yet.
Named parameters and SELECT IN clause Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Named parameters and SELECT IN clause

    I'm trying to execute a SQL in IN clause, using a List<String> object named groupList

    Code:
        	Map<String, Object> parameters = new HashMap<String, Object>();
    		parameters.put("appName", ApplicationName);
    		parameters.put("groupIds", groupList);
        	
        	String sql = "select COUNT(application.id) " +
    				"inner join application_groups on application_groups.groups = groups.id " +
    				"inner join application on application.id = application_groups.application " +
    				" where application.name = :appName and groups.name in (:groupIds)";
        	return (this.jdbcTemplate.queryForInt(sql, parameters)>0);
    But the code, it's raising one exception:

    Code:
    [Request processing failed; nested exception is org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL [select COUNT(application.id) inner join application_groups on application_groups.groups = groups.id inner join application on application.id = application_groups.application  where application.name = :appName and groups.name in (:groupIds)]; Invalid argument value: java.lang.ArrayIndexOutOfBoundsException; nested exception is java.sql.SQLException: Invalid argument value: java.lang.ArrayIndexOutOfBoundsException] with root cause
    java.lang.ArrayIndexOutOfBoundsException: 0
    What is wrong in my code? I should use another object different than List<string>?
    Last edited by CGarces; Dec 17th, 2012, 09:40 AM.

  • #2
    It should work, however it will only work with list which have elements... Judging by the stacktrace you are passing in an empty list and that isn't going to work.

    Comment


    • #3
      Originally posted by Marten Deinum View Post
      It should work, however it will only work with list which have elements... Judging by the stacktrace you are passing in an empty list and that isn't going to work.
      The hashmap parameters looks correct, the list contains one item.

      On debug mode I see this inside the map.
      Code:
      {appName=test1, groupIds=[ROLE_ADMIN]}

      Comment


      • #4
        Can you post the full stacktrace. You are using the NamedParameterJdbcTemplate aren't you?

        Comment


        • #5
          Originally posted by Marten Deinum View Post
          Can you post the full stacktrace. You are using the NamedParameterJdbcTemplate aren't you?
          Opps, I was using jdbcTemplate not NamedParameterJdbcTemplate.
          Problem solved

          Comment

          Working...
          X