Backup SQLite using Java

2019-08-12 03:42发布

I need to create a Java class that creates a backup of my database. My problem is, I don't know how to do this using a SQLite database. Can anyone show me how?

2条回答
走好不送
2楼-- · 2019-08-12 04:02

The easiest thing is to create a copy of the database file- assuming it is a disk-based DB.

查看更多
迷人小祖宗
3楼-- · 2019-08-12 04:19

If the database is reasonably small, you can just call BEGIN EXCLUSIVE TRANSACTION to prevent other processes from modifying the database, then copy the database file, then ROLLBACK TRANSACTION. If the file is huge, you'll have to use the online backup interface (if your Java bindings don't support it, use JNI).

Of course, if there's just your app using this database and you can be sure that nobody's going to modify the file while you're copying it, just go for it and copy.

查看更多
登录 后发表回答