I have a problem to attach a Database and insert all rows from attached databases to the main.
Here is my code.
public void selectOldDb(String dbName) throws Exception {
createNewDB();
Class.forName("org.sqlite.JDBC");
Connection connOldDb = DriverManager.getConnection("jdbc:sqlite:"+ dbName);
String newDbName = getDirToNewDb();
newDbName = newDbName + "auftraege.db";
Connection connNewDb = DriverManager.getConnection("jdbc:sqlite:"+ newDbName);
connNewDb.prepareStatement("ATTACH DATABASE \"" + connOldDb + "\" AS fromDB").execute();
connNewDb.prepareStatement("INSERT INTO main.auftraege SELECT * FROM fromDB.SendeDS").execute();
connNewDb.close();
connOldDb.close();
}
I become this error when i try to insert.
[SQLITE_ERROR] SQL error or missing database (no such table: fromDB.SendeDS)
What am I doing wrong?
The ATTACH DATABASE command expects a file name, but you give it the representation of a Connection object.
You don't need connOldDb, just use dbName instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With