Android

This topic applies to Java version only

Android is a new complete, open and free mobile platform. Android offers developers a java based software developer kit with lots of helpful APIs, including geolocational services. Of course, there is a database support as well: Android has a built-in support for SQLite database. The basic API is similar to standard JDBC API, however some effort was added to create some convenience methods:

public int delete(String table, String whereClause, String[] whereArgs)

public long insert(String table, String nullColumnHack, ContentValues values)

public Cursor query(boolean distinct, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy)

public long replace(String table, String nullColumnHack, ContentValues initialValues)

This may look better than SQL, but if you look closer you can see that all column names and selection criteria are specified as strings, so we still stay with a problem of run-time checking instead of compile-time.

Luckily even for this very early Android release we already have an alternative - db4o. Yes, db4o runs on Android out of the box and produces very competitive results as well. The following application compares db4o and SQLite usage for basic operations. It also contains some operation duration calculations that can be used to compare db4o vs SQLite performance. Please, note that these results are for an overview purpose only and there are many configuration settings that can change performance of both databases. Also running in emulator does not guarantee the same results as in real device. You can download the whole application code here.

Step by Step installation

The steps to install db4o on Android are quite simple thanks to Eclipse.

  1. Point your browser to http://developer.db4o.com/files/default.aspx. Here you have to choose stable, production or development release (I recommend the current production version) and then download the Java version of db4o.
  2. Copy db4o-xxx-java1.1.jar available in the lib folder of your db4o installation to a lib folder in your Android project root directory.
  3. Refresh the Eclipse project folders, click on lib, right-click on db4o-xxx-java1.1.jar  and select "Add to build path".
  4. You're done! You can now use db4o in your Android application and it will be deployed automatically when running the Android emulator.

Things to remember when using db4o under Andoid

  1. Use the Java 1.1 version of the db4o library available on the lib folder of your db4o installation (db4o-xxx-java1.1.jar). The other db4o Java versions still suffer from some issues with the way in which Android handles reflection.
  2. Open the database relative to your parent activity (context) data directory:
    Db4o.openFile(dbConfig(), db4oDBFullPath(context));

    private String db4oDBFullPath(Context ctx) {

          return ctx.getDataDir() + "/" + "dbfile.yap";

    }
    Otherwise Android security will prevent the creation of the database file.