title: how to resolve StatementCallback; bad SQL grammar?
body: <p>I am getting StatementCallback; bad SQL grammar exception but unable to identify</p>
  
  <p>MyMain.java</p>
  
  <pre><code>public class MyMain {
  
      public static void main(String[] args) {
          ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext.xml");
  
          ReportDao dao=(ReportDao)ctx.getBean("edao");  
  
          List&lt;Report&gt; aList=dao.getJobDetails();
          Report obj=null;
  
          Iterator iterator = aList.iterator();
  
          while (iterator.hasNext()) {
              obj = (Report) iterator.next();
              System.out.println(obj);
          }
  
      }
  }
  </code></pre>
  
  <p>ReportDao.java</p>
  
  <pre><code>public class ReportDao {
  
      private JdbcTemplate jdbcTemplate1;
  
      public void setJdbcTemplate1(JdbcTemplate jdbcTemplate) {
          this.jdbcTemplate1 = jdbcTemplate;
      }
  
      private final String sql_select_schedular_job_details = "SELECT 'SCHEDULE_TYPE',SCHEDULED_DATE,'EMAIL_IDS',LAST_RUN_DATE  FROM PIL_GUI_QUARTZ_REPORTS ";
  
      private String qry="select 1 from dual";
  
      public List&lt;Report&gt; getJobDetails() {
          List&lt;Report&gt; reportList = new ArrayList&lt;&gt;();
  
          try {
              reportList = jdbcTemplate1.query(sql_select_schedular_job_details, new ReportMapper());
              //System.out.println(jdbcTemplate1.query(qry, new DemoMapper()));
  
          } catch (Exception e) {
              e.printStackTrace();
          }
          return reportList;
      }
  
  }
  </code></pre>
  
  <p>ReportMapper.java</p>
  
  <pre><code>public class ReportMapper implements RowMapper&lt;Report&gt;{
  
      public Report mapRow(ResultSet rs, int rowNum) throws SQLException {
  
          Report report = new Report();
          report.setScheduledType(rs.getString("SCHEDULE_TYPE"));
          report.setScheduledDate(rs.getDate("SCHEDULED_DATE"));
          report.setEmailIds(rs.getString("EMAIL_IDS"));
          report.setLastRundDate(rs.getDate("LAST_RUN_DATE"));
  
          return report;
      }
  
  }
  </code></pre>
  
  <p>Report.java</p>
  
  <pre><code>public class Report {
  
      private String scheduledType;
      private Date scheduledDate;
      private String emailIds;
      private Date lastRundDate;
  
      public String getScheduledType() {
          return scheduledType;
      }
  
      public void setScheduledType(String scheduledType) {
          this.scheduledType = scheduledType;
      }
  
      public Date getScheduledDate() {
          return scheduledDate;
      }
  
      public void setScheduledDate(Date scheduledDate) {
          this.scheduledDate = scheduledDate;
      }
  
      public String getEmailIds() {
          return emailIds;
      }
  
      public void setEmailIds(String emailIds) {
          this.emailIds = emailIds;
      }
  
      public Date getLastRundDate() {
          return lastRundDate;
      }
  
      public void setLastRundDate(Date lastRundDate) {
          this.lastRundDate = lastRundDate;
      }
  
  }
  </code></pre>
  
  <p>Even if I have copied all the field names from DB and follow the same sequence in the mapper as the query but still getting exception, unable to know why. I query the same from SqlDeveloper and I am getting output. I tried with single_quote and without it also. This is a duplicate question but I am surprised why it is not working even the query is very simple, only a select statement. The table is inside synonym and the table name and the synonym name both are same.</p>
  
  <p>StackTrace</p>
  
  <pre><code>org.springframework.jdbc.BadSqlGrammarException: StatementCallback; bad SQL grammar [  SELECT 'SCHEDULE_TYPE', SCHEDULED_DATE , 'EMAIL_IDS', LAST_RUN_DATE  FROM PIL_GUI_QUARTZ_REPORTS ]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
  
      at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:231)
      at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:419)
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:474)
      at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:484)
      at com.myapp.dao.ReportDao.getJobDetails(ReportDao.java:30)
      at com.myapp.main.MyMain.main(MyMain.java:19)
  Caused by: java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist
  
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
      at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1017)
      at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:655)
      at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
      at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566)
      at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:202)
      at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:45)
      at oracle.jdbc.driver.T4CStatement.executeForDescribe(T4CStatement.java:766)
      at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:897)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1034)
      at oracle.jdbc.driver.OracleStatement.executeQuery(OracleStatement.java:1244)
      at oracle.jdbc.driver.OracleStatementWrapper.executeQuery(OracleStatementWrapper.java:420)
      at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:458)
      at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:408)
      ... 4 more
  </code></pre>