Does Android Support JDBC

Viewed 25619

I know that on Android there is android.database.sqlite package that provides helpful classes to manage the internal android database.

The question is - can I use the standard java.sql package to manipulate Android's database without using anything from android.database.sqlite.* I try to open connection using SQLite JDBC driver but when i added the library as e reference to the project eclipse crashes with "java heap out of memory ... couldn't convert to dalvik VM".

6 Answers

the JDBC driver is undocumented and unsupported. please do not use this code.

avoid java.sql and use android.database.sqlite instead.

Android has had full JDBC support from day one, but does not come with any drivers (at least officially). The general issue with JDBC drivers is that most rely on native code, which limits portability unless the developers specifically considered Android.

  • There seems to have been an unofficial SQLite JDBC driver, SQLite.JDBCDriver, with support for jdbc:sqlite:/path/to/db, in Android versions around 2.x. However, it appears to have long been removed (at least since 4.4.4).
  • SQLDroid and Xerial SQLite-JDBC are a third-party JDBC drivers which were written for Android. However, some users have reported various issues with these; I haven’t tried any of them myself.
  • Personally I have successfully used HSQLDB with a flat-file database (it can also run in client/server mode, which I have not tried on Android). Being pure Java (no native code), it is fully portable between Android and JRE.

Another issue you might run into when using JDBC on Android is that some Android mechanisms (such as content providers) expect a Cursor instance, as used by android.database.sqlite.*, whereas JDBC has ResultSet for that purpose. As these two are largely functional equivalents of each other, and Cursor is an interface, you might be able to write an adapter class which implements Cursor and translates its methods into their ResultSet equivalents.

There is another SQLite-jdbc driver out there. I got it working in my app as described here. However, there it is not supported for all Application Binary Interfaces, but the most devices are supported.

Related