【问题标题】:Truncate table in H2Database with DB2 syntax使用 DB2 语法截断 H2Database 中的表
【发布时间】:2020-01-29 18:21:36
【问题描述】:

我正在尝试使用 h2database 测试我的 DB2 查询,但在尝试截断表时遇到了问题。

这是我的查询:TRUNCATE TABLE SCHEMA.TABLE_NAME IMMEDIATE

错误:

Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "TRUNCATE TABLE TOPACC.STREAM_FORECAST IMMEDIATE[*]"; SQL statement:
TRUNCATE TABLE TOPACC.STREAM_FORECAST IMMEDIATE [42000-199]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)

我的配置:

private Properties hibernateProperties() {
    Properties properties = new Properties();
    properties.put("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
    properties.put("hibernate.show_sql", true);
    properties.put("hibernate.default_schema", "SCHEMA_NAME");
    properties.put("hibernate.connection.driver_class", "org.h2.Driver");
    properties.put("hibernate.connection.username", "NAME");
    properties.put("hibernate.connection.password", "");
    properties.put("hibernate.connection.url", "jdbc:h2:mem:testdb;MODE=DB2;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS SCHEMA_NAME");
    properties.put("hibernate.hbm2ddl.auto", "create");

    return properties;
}

【问题讨论】:

    标签: hibernate junit db2 h2 truncate


    【解决方案1】:

    H2 兼容模式不完全支持引擎特定的 SQL 语法。在这种特殊情况下,DB2 兼容模式不支持TRUNCATE TABLE 语句的IMMEDIATE 选项。

    兼容模式详情可参考H2 documentation

    【讨论】:

      猜你喜欢
      • 2011-03-01
      • 1970-01-01
      • 2021-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多