【问题标题】:H2 org.h2.jdbc.JdbcSQLSyntaxErrorException occurs when executing a script file in a h2 database在h2数据库中执行脚本文件时发生h2 org.h2.jdbc.JdbcSQLSyntaxErrorException
【发布时间】:2019-12-17 01:58:37
【问题描述】:

我使用java -cp h2-1.4.199.jar org.h2.tools.RunScript -url jdbc:h2:mem:db1 -script infra_params.sql命令在H2数据库中执行下面的sql脚本。

infra_params.sql 文件:-

DROP TABLE IF EXISTS `infrastructure_parameter`;

CREATE TABLE `infrastructure_parameter` (
`id` varchar(36) NOT NULL,
`created_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`modified_timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`NAME` varchar(255) DEFAULT NULL,
`PROPERTIES` varchar(255) DEFAULT NULL,
`ready` tinyint(1) DEFAULT '0',
`TYPE` varchar(255) DEFAULT NULL,
 PRIMARY KEY (`id`),
 UNIQUE KEY `UNQ_infrastructure_parameter_0` (`NAME`,`PROPERTIES`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8;

LOCK TABLES `infrastructure_parameter` WRITE;

但它给出了以下异常:-

Exception in thread "main" org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "

LOCK[*] TABLES `INFRASTRUCTURE_PARAMETER` WRITE "; SQL statement:


LOCK TABLES `infrastructure_parameter` WRITE [42000-199]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:451)
at org.h2.message.DbException.getJdbcSQLException(DbException.java:427)
at org.h2.message.DbException.get(DbException.java:205)
at org.h2.message.DbException.get(DbException.java:181)
at org.h2.message.DbException.getSyntaxError(DbException.java:229)
at org.h2.command.Parser.getSyntaxError(Parser.java:989)
at org.h2.command.Parser.parsePrepared(Parser.java:951)
at org.h2.command.Parser.parse(Parser.java:788)
at org.h2.command.Parser.parse(Parser.java:764)
at org.h2.command.Parser.prepareCommand(Parser.java:683)
at org.h2.engine.Session.prepareLocal(Session.java:627)
at org.h2.engine.Session.prepareCommand(Session.java:565)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1292)
at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:217)
at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205)
at org.h2.tools.RunScript.process(RunScript.java:261)
at org.h2.tools.RunScript.process(RunScript.java:192)
at org.h2.tools.RunScript.process(RunScript.java:328)
at org.h2.tools.RunScript.runTool(RunScript.java:143)
at org.h2.tools.RunScript.main(RunScript.java:70)

任何有关如何解决此问题的帮助将不胜感激。

【问题讨论】:

    标签: sql database jdbc utf-8 h2


    【解决方案1】:

    LOCK TABLES 是 MySQL 特有的命令,H2 不支持。

    您需要将其从文件中删除。

    如果你真的需要在 MySQL 和 H2 中使用相同的脚本,并且在 MySQL 中需要这个命令,你可以尝试将它包装成executable comment。 MySQL 与其他数据库不同,在/*! … */ cmets 中执行代码。

    /*! LOCK TABLES `infrastructure_parameter` WRITE; */

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-27
      • 2021-12-01
      • 2021-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多