[英]H2 database complaints about sql syntax error with a valid mysql query
我创建了一个内存H2数据库( http://www.h2database.com/html/features.html ),如下所示
public static HikariConfig createHikariConfigH2(String schema, String pathToSchemaSql) {
LOGGER.info("Creating schema {} and execute sql {}", schema, pathToSchemaSql);
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:h2:mem:" + schema + ";"
+ "MODE=MySQL;DATABASE_TO_LOWER=TRUE;CASE_INSENSITIVE_IDENTIFIERS=TRUE"
+ ";DB_CLOSE_DELAY=-1" + ";INIT= drop schema if exists " + schema + " CASCADE\\;create schema " + schema
+ "\\;SET SCHEMA " + schema + "\\;"
+ "runscript from 'classpath:/" + pathToSchemaSql + "'");
config.setUsername("sa");
config.setPassword("");
return config;
}
然后,我尝试如下运行SQL查询
HikariConfig config = createHikariConfigH2(“schema”, “a.sql”);
try (HikariDataSource master = new HikariDataSource(config);
Connection conn = master.getConnection();
PreparedStatement stmt = conn.prepareStatement(
"DELETE mt FROM tableA AS mt,tableB AS et WHERE mt.id = et.id AND et._iud = 'D'")) {
try (ResultSet result = stmt.executeQuery()) {
List<String> tables = new ArrayList<>();
while (result.next()) {
String tableName = result.getString(1);
tables.add(tableName);
}
}
}
但是它抱怨语法错误,但是相同的查询在正常的mysql db上运行良好 。
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "delete mt from tableA as mt,[*]tableB as et where mt.id = et.id and et._iud = 'D' "; SQL statement:
DELETE mt FROM tableA AS mt,tableB AS et WHERE mt.id = et.id AND et._iud = 'D' [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.prepareCommand(Parser.java:686)
at org.h2.engine.Session.prepareLocal(Session.java:627)
在mysql兼容性部分( http://www.h2database.com/html/features.html#compatibility )中,我找不到与此相关的任何内容。
有人可以帮忙吗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.