I am using SQLite in a project used by an android application. Currently I am using the SQLite implementation provided in android.database.sqlite
.
I want to make a desktop application which uses the same codebase. So I need to separate all the shared behaviour into a separate portable project/jar.
My problem is I'm currently making heavy use of android.database.sqlite
. If possible I do not want to re-write every database access call to be compatible with JDBC or whatever I will have to use without using the android provided SQLite.
To solve this problem with minimal impact on the existing code. I intent to write a SQLite interface (compatible with android.database.sqlite
) which the shared code will use... on android it will be implemented trivially by android.database.sqlite
, and on the desktop it will be implemented by somehow mutilating SQLite through JDBC to match android.database.sqlite
.
This is proving difficult as I often supply Object[]
arrays to be bound to prepared statements which JDBC requires strict typing, and I am not familiar with JDBC at all.
Is there any other way to use SQLite in Java which is similar to android.database.sqlite
, or any other approaches which may save me the effort (and inevitable debugging) associated with re-writing many database access points?
Disclamer: I have never until now tried using JDBC.
Simplified question: What is the best way to use SQLite in java? JDBC, other?
I think creating a wrapper would be a good idea, but may involve a lot of effort in terms of development as well as testing. Maybe you can start a project on google and get a few more people involved.
On a side note, I believe there's already such a project on google code called sqldroid
Here is what I would do:
What this means in your case is:
This way, your application will become abstracted from the underlying database which is being used. This will improve the portability.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With