配置mybatis跳过由/*…*/sql脚本中的样式注解

ghhaqwfi  于 2021-07-06  发布在  Java
关注(0)|答案(2)|浏览(424)

我正试图通过org.xerial sqlite jdbc connector和mybatis将wikipedia dumps(例如,这个)加载到sqlite数据库中,这是一系列的.sql脚本,但是在某些//使用以下错误设置文件开头的注解样式:

org.apache.ibatis.jdbc.RuntimeSqlException: Error executing: /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */
.  Cause: java.sql.SQLException: not implemented by SQLite JDBC driver
    at org.apache.ibatis.jdbc.ScriptRunner.executeLineByLine(ScriptRunner.java:159)
    at org.apache.ibatis.jdbc.ScriptRunner.runScript(ScriptRunner.java:119)
    at com.tracesemantics.knowledgeengine.DatabaseConnector.loadSQLFile(DatabaseConnector.java:120)
    at com.tracesemantics.knowledgeengine.DatabaseConnector.loadSQLFiles(DatabaseConnector.java:67)
    at com.tracesemantics.knowledgeengine.KnowledgeEngine.loadWikimediaDumpsIntoDatabase(KnowledgeEngine.java:155)
    at com.tracesemantics.knowledgeengine.KnowledgeEngine.call(KnowledgeEngine.java:119)
    at com.tracesemantics.knowledgeengine.KnowledgeEngine.call(KnowledgeEngine.java:1)
    at picocli.CommandLine.executeUserObject(CommandLine.java:1933)
    at picocli.CommandLine.access$1200(CommandLine.java:145)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2332)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2326)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2291)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2159)
    at picocli.CommandLine.execute(CommandLine.java:2058)
    at com.tracesemantics.knowledgeengine.KnowledgeEngine.main(KnowledgeEngine.java:93)
Caused by: java.sql.SQLException: not implemented by SQLite JDBC driver
    at org.sqlite.jdbc3.JDBC3Statement.unused(JDBC3Statement.java:387)
    at org.sqlite.jdbc3.JDBC3Statement.setEscapeProcessing(JDBC3Statement.java:382)
    at org.apache.ibatis.jdbc.ScriptRunner.executeStatement(ScriptRunner.java:243)
    at org.apache.ibatis.jdbc.ScriptRunner.handleLine(ScriptRunner.java:223)
    at org.apache.ibatis.jdbc.ScriptRunner.executeLineByLine(ScriptRunner.java:152)
    ... 14 common frames omitted

输入文件的开头是:

-- MySQL dump 10.16  Distrib 10.1.45-MariaDB, for debian-linux-gnu (x86_64)
    --
    -- Host: 10.64.48.13    Database: enwiki
    -- ------------------------------------------------------
    -- Server version       10.1.43-MariaDB

    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8mb4 */;
    /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
    /*!40103 SET TIME_ZONE='+00:00' */;
    /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

我认为这些评论是为了给mysql数据库提供指导。考虑到sqlite不支持这些注解,有没有办法配置jdbc驱动程序或mybatis来忽略这些注解,以便将数据导入数据库?
任何帮助都将不胜感激。

tv6aics1

tv6aics11#

哦,找到了解决办法。。。

scriptRunner.setEscapeProcessing(false);
5w9g7ksd

5w9g7ksd2#

你也知道这样的评论“/。。。布拉布拉…/”。
这在你脑子里肯定不管用,但它管用。
因此,我建议您将注解改为“/…
/”去“布拉布拉”。
“--”注解的开头可以忽略该行而不运行。
例如>
/!40101 set@old_character_set_client=@@character_set_client/;
=>
--40101 set@old\u character\u set\u client=@@character\u set\u client

相关问题