hsql bad sql语法异常
Posted
技术标签:
【中文标题】hsql bad sql语法异常【英文标题】:hsql bad sql grammar exception 【发布时间】:2018-03-22 18:07:30 【问题描述】:我在数据库中创建一个内存表如下:
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())
);
【问题讨论】:
插入脚本中的值在哪里? 向我们提供您尝试插入的示例数据。 @anonyXmous 添加 你使用的是什么版本的 HSQLDB? @GordThompson 2.3.2 【参考方案1】:我需要用java.sql.Timestamp.valueOf(time);
包装LocalDateTime
变量
【讨论】:
... 或升级到 HSQLDB 2.4.0,它引入了对java.time.LocalDateTime
等的支持。在 Java 8 中。
另外,请注意,将 java.time.LocalDateTime
转换为 java.sql.Timestamp
将施加可能会改变值的时区规则。例如,java.sql.Timestamp
不能在“美国/丹佛”时区表示“2018-03-11T02:00:00”,因为由于切换到夏令时,该时区根本不存在该时间。以上是关于hsql bad sql语法异常的主要内容,如果未能解决你的问题,请参考以下文章
从 DatabaseSwingManager 连接时 HSQL 服务器模式引发异常 java.sql.SQLTransientConnectionException
无法获得 JDBC 连接;嵌套异常是 java.sql.SQLException:无法加载 JDBC 驱动程序类 'org.hsql.jdbcDriver'