java - sqlite4java no such table error by attaching another database -


i'm using sqlite4java handle sqlite db. want copy table database dbtest. found code here on stackoverflow. error. first of open connection new created database , afterwards attach other database following command:

attach database database database;

this works fine. dbtest has been opended earliere new database. want copy tables: hence, table created , same in other database.

insert dbtest.routing (id, source, destination, metadata, zone_src, zone_dst,cost) select * database.routing;

but after executing error:

com.almworks.sqlite4java.sqliteexception: [1] db[1] exec() no such table: dbtest.routing

i tried sqlite studio , there working without problems, cannot attach database there (this done automatically). have use notation use 2 databases?

edit: use answer cl. leads new issue:

com.almworks.sqlite4java.sqliteexception: [1] db[1] exec() no such table: second.routing

what did change?

attach database database second; //new name database file , attached second, because if use debug function says: database second in use.

if use command error mentioned above.

insert routing (id, source, destination, metadata, zone_src, zone_dst,cost) select * second.routing;

problem solved using absolute path database file.

the name of attached databases not file name whatever you've specified name in as clause of attach statement.

neither name of main database (the database other database attached) file name. name main.

to specify name of table in main database, use main.routing, or routing.


please note sqlite happy creating new database if file not yet exist, have ensure give correct file name attach statement. if database file not named database or if not in current directory, second database empty. recommended give complete file path, this:

attach database '/some/where/whatever.db' second; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -