gpt4 book ai didi

mysql - 如何将 mysql 转储加载到 hsqldb 数据库?

转载 作者:IT老高 更新时间:2023-10-29 00:07:19 25 4
gpt4 key购买 nike

我有一个在 mysql 中创建数据库的 sql 文件:

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`machine`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`machine` (
`id` INT NOT NULL ,
`name` VARCHAR(45) NULL ,
PRIMARY KEY (`id`) );


SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

现在我想将这个文件加载到 hsqldb 2 数据库中。我需要在 mysql 转储中更改什么才能将数据加载到 hsqldb 中?

目前我使用这段代码(groovy)来执行sql文件:

def embeddedDbSettings = [url:'jdbc:hsqldb:file:mydb', user:'sa', password:'', driver:'org.hsqldb.jdbcDriver'];
sql = Sql.newInstance(embeddedDb);
sql.executeInsert new File("./sql/create_database.sql").text;

而且我一直遇到这个加密异常:

Exception in thread "main" java.sql.SQLException: unknown token
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.executeUpdate(Unknown Source)
at groovy.sql.Sql.executeInsert(Sql.java:1440)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at de.hpi.ecir.eval_script.Convert2Excel.main(Convert2Excel.groovy:37)
Caused by: org.hsqldb.HsqlException: unknown token
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.ParserBase.read(Unknown Source)
at org.hsqldb.ParserDDL.compileCreate(Unknown Source)
at org.hsqldb.ParserCommand.compilePart(Unknown Source)
at org.hsqldb.ParserCommand.compileStatements(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 13 more

最佳答案

  1. 删除所有 SET 行
  2. 将创建数据库的命令更改为:CREATE SCHEMA mydb AUTHORIZATION DBA
  3. 删除所有如果不存在 - hsqldb 不支持此命令
  4. 删除所有表扬(不是必需的,但您在本文中找到的代码需要)
  5. 删除所有`
  6. 用 bool 值替换 TINYINT( bool 值的 mysql 等价物)
  7. 分别执行每条命令:

    String[] commands = new File("./sql/create_database.sql").text.split(";");

    for(String command: commands)
    {

    // new line is a delimiter in hsqldb

    sql.execute command.replace("\n", " ");
    }

    // remember to call shutdown otherwise hsqldb will not save your data
    sql.execute "SHUTDOWN"
    sql.close();

关于mysql - 如何将 mysql 转储加载到 hsqldb 数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3811906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com