Max
Max

Reputation: 21

Backup SQLite using Java

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?

Upvotes: 2

Views: 3070

Answers (2)

MaxSem
MaxSem

Reputation: 3547

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.

Upvotes: 4

andig
andig

Reputation: 13868

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

Upvotes: 0

Related Questions