简体   繁体   English

为什么不能在JDBC中使用.dump命令?

[英]Why can I not use the .dump command with JDBC?

I am trying to merge two sqlite tables by dumping the contents of one into another. 我试图通过将一个的内容转储到另一个合并两个sqlite表。 However, each time I attempt this, a syntax error is thrown, stating "[SQLITE_ERROR] SQL Error or missing database (near "sqlite3": syntax error)" 但是,每次尝试此操作时,都会引发语法错误,指出“ [SQLITE_ERROR] SQL错误或缺少数据库(在“ sqlite3”附近:语法错误)”

conn is the connection of the original database, which I send all sql commands. conn是原始数据库的连接,我发送了所有sql命令。 newConn is the connection of the database to be merged. newConn是要合并的数据库的连接。

How can I fix this issue? 如何解决此问题? Thank you in advance! 先感谢您!

EDIT: I just wanted to make sure this doesn't get closed for being a duplicate. 编辑:我只是想确保这不会因为重复而关闭。 I used the sql code from here , but it's still causing problems. 我从这里使用了sql代码,但仍然会引起问题。

        newConn = DriverManager.getConnection("jdbc:sqlite:" + path);

        String sqlMerge =  "sqlite3 ? .dump";
        conn.setAutoCommit(false);
        PreparedStatement pstmt1 = conn.prepareStatement(sqlMerge);
        pstmt1.setString(1, newConn.getCatalog());
        pstmt1.executeUpdate();
        conn.commit();

.dump is a feature of the SQLite command-line shell. .dump是SQLite命令行shell的功能。 It is not recognized by the SQLite dialect of the SQL language. SQL语言的SQLite方言无法识别它。 You can either invoke the command-line shell from within Java or perform the equivalent operation using actual SQL commands via JDBC (to read the data) and Java file operations (to write the required dump file). 您可以从Java内部调用命令行外壳程序,也可以使用实际的SQL命令通过JDBC(读取数据)和Java文件操作(写入所需的转储文件)执行等效操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM