title: Spring JDBCTemplate throwing BadSqlGrammarException
body: <p>I have an SQL query that is executed using Spring JDBCTemplate to retrieve data from an Oracle DB. While executing the statement, <code>org.springframework.jdbc.BadSqlGrammarException</code> is thrown.</p>
  
  <p>The same SQL statement returns proper results when run in the SQL Plus console.</p>
  
  <p>Below is the code that I am trying to execute:</p>
  
  <pre><code>String query = "SELECT DISTINCT O.ORGID FROM ORGANISATIONS O WHERE O.ORGTYPE NOT IN ('P','G') AND O.USERID = 40";
  
  ArrayList&lt;Organisations&gt; orgsList = new  ArrayList&lt;Organisations&gt;();
  Object[] paramsArray = new Object[]{};
  
  orgsList = (ArrayList&lt;Organisations&gt;) getJdbcTemplate().query(query.toString(), paramsArray ,
              new RowMapper&lt;Organisations&gt;(){
          public MetricsRoleMap mapRow(ResultSet rs, int rowNum) throws SQLException {
              // Data retrieval code;
          };
      });
  </code></pre>
  
  <p>Here is the error generated:</p>
  
  <pre><code>org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [ SELECT DISTINCT O.ORGID FROM ORGANISATIONS O WHERE O.ORGTYPE NOT IN ('P','G') AND O.USERID = 40]; nested exception is java.sql.SQLException: Invalid column name
      at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:660) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:695) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:727) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:737) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:787) [spring-jdbc-4.0.5.RELEASE.jar:4.0.5.RELEASE]
  </code></pre>
  
  <p>Similar code that I wrote for another method works well. I think there is a minor mistake here, but I am unable to find it.</p>