0

当我关闭 h2 连接(发布数据库)并尝试连接到另一个 h2 数据库(调试数据库)时遇到问题。

要连接的片段:

this.connection = new JdbcConnectionSource(connectionString);

断开连接的片段:

this.connection.close();

连接字符串:

jdbc:h2:file:/data/data/my.app/databases/myapp
jdbc:h2:file:/data/data/my.app/testdatabases/myapp

然后不使用“新”连接,而是使用旧连接。我正在为数据库使用不同的目录。在这两种情况下,当我尝试在 database1 和 database2 之间切换时,.lock 和 .trace 文件都不会在它们的目录中删除。

我想排除我这边的实施失败。我在 android 4.2.2 上使用 h2(当前版本)和 ormlite。

4

1 回答 1

0

Then instead of using the "new" connection the old one is used.

If you are creating a new ConnectionSource then you will need to re-create all of your DAO classes and clear the DAO cache from within the DaoManager. Each of the DAO classes has a copy of the old connection source that it uses.

ConnectionSource connectionSource = new JdbcConnectionSource(connectionString);
DaoManager.clearCache();
Dao<Foo,Integer> fooDao = DaoManager.createDao(connectionSource, Foo.class);
...
于 2013-06-18T21:11:44.113 回答