1

I am trying to merge two sqlite tables by dumping the contents of one into another. However, each time I attempt this, a syntax error is thrown, stating "[SQLITE_ERROR] SQL Error or missing database (near "sqlite3": syntax error)"

conn is the connection of the original database, which I send all sql commands. newConn is the connection of the database to be merged.

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.

        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();

1 Answers1

2

.dump is a feature of the SQLite command-line shell. It is not recognized by the SQLite dialect of the SQL language. 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).

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418