如何解决StatementCallback;坏SQL语法?

时间:2017-05-01 14:08:38

标签: java spring jdbc

我收到StatementCallback;错误的SQL语法异常但无法识别

MyMain.java

public class MyMain {

    public static void main(String[] args) {
        ApplicationContext ctx=new ClassPathXmlApplicationContext("ApplicationContext.xml");

        ReportDao dao=(ReportDao)ctx.getBean("edao");  

        List<Report> aList=dao.getJobDetails();
        Report obj=null;

        Iterator iterator = aList.iterator();

        while (iterator.hasNext()) {
            obj = (Report) iterator.next();
            System.out.println(obj);
        }

    }
}

ReportDao.java

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<Report> getJobDetails() {
        List<Report> reportList = new ArrayList<>();

        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;
    }

}

ReportMapper.java

public class ReportMapper implements RowMapper<Report>{

    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;
    }

}

Report.java

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;
    }

}

即使我从数据库中复制了所有字段名称并在映射器中按照与查询相同的顺序但仍然出现异常,无法知道原因。我从SqlDeveloper查询相同的内容,我得到了输出。我尝试使用single_quote而没有它。这是一个重复的问题,但我很惊讶为什么即使查询非常简单,只有一个select语句也不起作用。该表在同义词内,表名和同义词名称都相同。

栈跟踪

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

0 个答案:

没有答案