MySQLの最新のJDBCドライバでは動作しない
前ページのサンプルプログラムの設定方法で、MySQLのJDBCドライバのファイル名まで指定したのには理由があります。この後にリリースされた2010年11月の時点で最新のmysql-connector-java-5.1.13-bin.jar(以降、新しいJDBCドライバ)では、このサンプルプログラムは動かないのです。この新しいJDBCドライバを外部JARに指定した直後、Eclipseのコンソールにはリスト4-1のようなメッセージが表示され、プログラムは実行できません。
ちなみに新しいJDBCドライバを指定して、一度、このメッセージが表示されると、外部JARに古いJDBCドライバ(mysql-connector-java-5.1.10-bin.jar)を指定しても、そのプロジェクトは二度と実行できませんでした。新しくプロジェクトを作り直したほうがよさそうです。
古いJDBCドライバなら問題ないのか?
私はMySQLに詳しいわけではないので、これらのドライバの間にどのような違いがあるのかは分かりませんが、近いバージョンのドライバですら、Androidでの動作ではこのような違いがあります。
では古いドライバを使い続ければ、それでよいのかというと、話はそれほど単純でもありません。古いJDBCドライバでサンプルプログラムが動作することは確認していますが、このJDBCドライバを外部JARに指定すると、Eclipseのコンソール(図4-1)にはリスト4-2のような警告メッセージが大量に表示されます。そして、それを無視して実行するとリスト4-3のような警告メッセージがさらに追加されます。
サンプルプログラムは動作しますが、このような警告を無視するだけの勇気があるか否かは、担当者の胆力が試される場面です。少なくとも私は読者に心配せずに使用してよいというだけの根拠を持っていません。
次のページではMicrosoft SQL Serverを使う場合について説明します。
[2010-11-22 20:41:55 - MyDBApp] UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.util.ExceptionWithContext [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.util.ExceptionWithContext.withContext(ExceptionWithContext.java:46) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:340) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:131) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:85) (…… 省略 ……) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.cf.code.Ropper.doit(Ropper.java:649) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.cf.code.Ropper.convert(Ropper.java:253) [2010-11-22 20:41:55 - MyDBApp] at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:252) [2010-11-22 20:41:55 - MyDBApp] ... 31 more ...while processing reuseAndReadPacket (Lcom/mysql/jdbc/Buffer;I)Lcom/mysql/jdbc/Buffer; ...while processing com/mysql/jdbc/MysqlIO.class [2010-11-22 20:41:55 - MyDBApp] 1 error; aborting [2010-11-22 20:41:55 - MyDBApp] Conversion to Dalvik format failed with error 1
[2010-11-22 10:17:24 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) [2010-11-22 10:17:24 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) (…… 省略 ……) [2010-11-22 10:17:30 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) [2010-11-22 10:17:32 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.)
[2010-11-22 00:15:32 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) [2010-11-22 00:15:32 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) (…… 省略 ……) [2010-11-22 00:15:38 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) [2010-11-22 00:15:40 - MyDBPrj3] warning: Ignoring InnerClasses attribute for an anonymous inner class that doesn't come with an associated EnclosingMethod attribute. (This class was probably produced by a broken compiler.) [2010-11-22 00:15:42 - MyDBPrj3] ------------------------------ [2010-11-22 00:15:42 - MyDBPrj3] Android Launch! [2010-11-22 00:15:42 - MyDBPrj3] adb is running normally. [2010-11-22 00:15:42 - MyDBPrj3] Performing myDB.pac.MyDBApp activity launch [2010-11-22 00:15:42 - MyDBPrj3] Automatic Target Mode: Unable to detect device compatibility. Please select a target device. [2010-11-22 00:16:06 - MyDBPrj3] 警告: Application does not specify an API level requirement! [2010-11-22 00:16:06 - MyDBPrj3] Device API version is 7 (Android 2.1-update1) [2010-11-22 00:16:06 - MyDBPrj3] Uploading MyDBPrj3.apk onto device 'emulator-5554' [2010-11-22 00:16:07 - MyDBPrj3] Installing MyDBPrj3.apk... [2010-11-22 00:16:18 - MyDBPrj3] 成功! [2010-11-22 00:16:18 - MyDBPrj3] Starting activity myDB.pac.MyDBApp on device

