sqlite4java没有这样的表错误通过附加另一个数据库 [英] sqlite4java no such table error by attaching another database

查看:288
本文介绍了sqlite4java没有这样的表错误通过附加另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用sqlite4java来处理sqlite db。我想现在将一个表从数据库复制到dbtest。所以我在stackoverflow上找到了代码。但我总是一个错误。首先,我打开一个连接到我的新创建的数据库,然后用下面的命令附加其他数据库:

I'm using sqlite4java to handle with sqlite db. I want now to copy a table from database to dbtest. So I found the code here on stackoverflow. But I get always an error. First of all I open a connection to my new created database and afterwards I attach the other database with the following command:


ATTACH DATABASE数据库AS数据库;

ATTACH DATABASE database AS database;

这很好。 dbtest已被打开作为新的数据库。
然后我想复制表:因此,表已经创建并且与其他数据库中的表一样。

This works fine. dbtest has been opended earliere as new database. Then I want to copy the tables: Hence, the table is already created and it is the same as in the other database.


INSERT INTO dbtest.Routing(id,source,destination,metadata,zone_src,zone_dst,cost)SELECT * FROM database.Routing;

INSERT INTO dbtest.Routing (id, source, destination, metadata, zone_src, zone_dst,cost) SELECT * FROM database.Routing;

但是执行后我得到的错误:

But after executing this I get the error:


com.almworks.sqlite4java.SQLiteException:[1] DB [1] exec )没有这样的表:dbtest.Routing

com.almworks.sqlite4java.SQLiteException: [1] DB[1] exec() no such table: dbtest.Routing

我也试过sqlite Studio和它的工作没有任何问题,但我不能在这里附加数据库(这是自动完成的)。我必须使用另一个符号来使用两个数据库吗?

I tried it also with sqlite Studio and there it is working without any problems, but I cannot attach a database there (this is done automatically). Do I have to use another notation to use two databases?

EDIT
我现在使用CL的答案。但这会导致新的问题:

EDIT: I use now the answer from CL. But this leads to the new issue:


com.almworks.sqlite4java.SQLiteException:[1] DB [1] exec table:second.Routing

com.almworks.sqlite4java.SQLiteException: [1] DB[1] exec() no such table: second.Routing

我改变了什么?


ATTACH DATABASE数据库AS第二; //数据库文件的新名称,它将作为第二个附加,因为如果我使用调试功能,它说:数据库第二已经在使用。

ATTACH DATABASE database AS second; //new name for the database file and it will be attached as second, because if I use the debug function it says: Database second already in use.

如果我使用这个命令,我得到上面提到的错误。

If I use this command I get the error mentioned above.


INSERT INTO路由(id,source,destination,metadata ,zone_src,zone_dst,cost)SELECT * FROM second.Routing;

INSERT INTO Routing (id, source, destination, metadata, zone_src, zone_dst,cost) SELECT * FROM second.Routing;

使用数据库文件的绝对路径解决问题。 / p>

Problem solved by using the absolute path for the database file.

推荐答案

附件数据库的名称不是其文件名, ATTACH 语句的 AS 子句。

The name of attached databases is not its file name but whatever you've specified as name in the AS clause of the ATTACH statement.

是主数据库(附加其他数据库的数据库)的文件名称。它的名称始终是 main

Neither is the name of the main database (the database to which the other database was attached) its file name. Its name always is main.

要指定主数据库中的表的名称,请使用 main.Routing ,或只是路由

To specify the name of a table in your main database, use main.Routing, or just Routing.

请注意,如果文件尚不存在,SQLite非常满意创建一个新的数据库,所以你必须确保给 ATTACH 语句。
如果您的数据库文件未命名为 database 或如果它不在当前目录中,则 second 数据库将为空。
强烈建议您始终提供完整的文件路径,如下所示:

Please note that SQLite is perfectly happy with creating a new database if the file does not yet exist, so you have to ensure to give the correct file name to the ATTACH statement. If your database file is not named database or if it is not in the current directory, the second database will be empty. It is strongly recommended to always give the complete file path, like this:

ATTACH DATABASE '/some/where/whatever.db' AS second;

这篇关于sqlite4java没有这样的表错误通过附加另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆