使用Java备份SQLite [英] Backup SQLite using Java
问题描述
我需要创建一个Java类,该类创建数据库的备份.我的问题是,我不知道如何使用SQLite数据库执行此操作.谁能告诉我如何?
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?
推荐答案
如果数据库相当小,则可以调用BEGIN EXCLUSIVE TRANSACTION
来阻止其他进程修改数据库,然后复制数据库文件,然后复制ROLLBACK TRANSACTION
.如果文件很大,则必须使用在线备份界面(如果Java绑定没有,要支持它,请使用JNI).
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.
这篇关于使用Java备份SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!