iosj2objc

How to convert sqlite-jdbc-3.8.11.1.jar to iOS using j2objc?


I'm converting a java project to objective c (on iOS).

However, when I run it, it's hitting:

*** Terminating app due to uncaught exception 'JavaLangClassNotFoundException', reason: 'java.lang.ClassNotFoundException: org.sqlite.JDBC'

I've already added "$CURRENT_DIR/libs/sqlite-jdbc-3.8.11.1.jar" to the sourcepath.

I've even tried to get the source code from bitbucket: https://bitbucket.org/xerial/sqlite-jdbc/commits/tag/sqlite-jdbc-3.7.2

However, it's giving me multitude errors after translating it:

src-sqlite-test/org/sqlite/SQLiteErrorCode.java:88: error: illegal start of expression for (SQLiteErrorCode each : )

src-sqlite-test/org/sqlite/core/CorePreparedStatement.java:118: error: ')' expected switch (1.$SwitchMap$org$sqlite$SQLiteConfig$DateClass[conn.dateClass.ordinal()]){

src-sqlite-test/org/sqlite/core/CorePreparedStatement.java:118: error: case, default, or '}' expected switch (1.$SwitchMap$org$sqlite$SQLiteConfig$DateClass[conn.dateClass.ordinal()]) {

Another option is to use ios native sqlite library to access the database.


Solution

  • Consider switching to SQLighter (https://github.com/vals-productions/sqlighter), which is a Java ORM that uses the native SQLite libraries built into Android and iOS. It's small and fast, thanks to the native platform support, plus it's generally easier to write Java code to ORMs, requiring less boilerplate code.

    J2ObjC doesn't support JDBC, as it's a poor choice for mobile apps (slow, bulky) and database vendors don't provide iOS versions of their drivers. In theory you could port Xerial by also porting JDBC, but that's a big task that is likely to perform poorly in your app. The j2objc team has a saying that applies here: "just because something can be translated doesn't mean it should be." :-)