hsql坏sql语法异常

时间:2018-03-22 18:07:31

标签: java sql jdbc hsqldb

我在数据库中创建一个内存表,如下所示:

CREATE TABLE ERRORCONTEXT (
  eventId         INTEGER,
  processStartTsp TIMESTAMP,
  processEndTsp TIMESTAMP,
  errorStack LONGVARCHAR,
  tradeReference VARCHAR(30),
  integrationStatus  VARCHAR(50),
  integrationStatusDescription LONGVARCHAR
);

我的插入脚本:

insert into ERRORCONTEXT (eventId,processStartTsp,processEndTsp,errorStack,tradeReference,integrationStatus,integrationStatusDescription) values(?,?,?,?,?,?,?)

我有上面的sql脚本,我无法插入到hsql db并获得以下异常。

Caused by: org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [INSERT INTO ERRORCONTEXT (eventId, processStartTsp,processEndTsp,errorStack,tradeReference,integrationStatus,integrationStatusDescription)
VALUES (?,?,?,?,?,?,?);]; nested exception is java.sql.SQLSyntaxErrorException: incompatible data type in conversion

我插入的pojo如下:

public class TradeProcessingContext {

    private Long eventId;
    private String tradeReference;
    private LocalDateTime processStartTsp;
    private LocalDateTime processEndTsp;
    private String errorStack;
    private IntegrationStatus integrationStatus;
    private String integrationStatusDescription;


}

我不明白不兼容类型错误的来源。我想插入的示例数据如下:

eventId=54611889, 
tradeReference=TRADE_REF-3033372, 
processStartTsp=2018-03-22T18:20:31.643, 
processEndTsp=2018-03-22T18:20:32.688, 
errorStack= (this is the full exception stack trace)
integrationStatus=SENT,
integrationStatusDescription=PreparedStatementCallback; bad SQL grammar [insert into aqapp.nvision_tradess(event_id, trade_reference, event_state, process_start_tsp,process_end_tsp,error_stack) values(?,?,?,?,?,?)]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist

integrationStatus =>我的枚举类型的字符串值

integrationStatusDescription =>例外getMessage()

HSQL Maven:

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.2</version>
    </dependency>

底层DAO方法:

public boolean log(final TradeProcessingContext tc) {
    int affected = jdbcTemplate.update(SQLQueryHelper.getQuery(Queries.LOG_QUERY),
            tc.getEventId(),
            tc.getProcessStartTsp(),
            tc.getProcessEndTsp(),
            tc.getErrorStack(),
            tc.getTradeReference(),
            String.valueOf(tc.getIntegrationStatus()),
            String.valueOf(tc.getIntegrationStatusDescription())
    );

1 个答案:

答案 0 :(得分:0)

我需要用LocalDateTime

包装java.sql.Timestamp.valueOf(time);变量