SHOEISHA iD

※旧SEメンバーシップ会員の方は、同じ登録情報(メールアドレス&パスワード)でログインいただけます

DeveloperZine(デベロッパージン)- エンジニアの意思決定を支える技術情報メディア ProductZine

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

Androidを使ったクライアント/サーバー・データベースシステム

Androidクライアントからデータベースサーバーへのアクセス

Androidを使ったクライアント/サーバー・データベースシステム 第1回


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を使う場合について説明します。

リスト4-1 最新のJDBCドライバを外部JARとして指定したときに、Eclipseのコンソールに出力される警告メッセージ。コンパイルも実行もできない。
[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
リスト4-2 古いJDBCドライバを外部JARとして指定したときに、Eclipseのコンソールに出力される警告メッセージ(図4-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.)
リスト4-3 古いJDBCドライバを使ってプログラムを実行したときに、Eclipseのコンソールに出力される警告メッセージ
[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 
図4-1 Eclipseのコンソールに警告が出力される
図4-1 Eclipseのコンソールに警告が出力される

次のページ
Microsoft SQL Serverに、Android端末からアクセスする

この記事は参考になりましたか?

Androidを使ったクライアント/サーバー・データベースシステム連載記事一覧
この記事の著者

秋月 巌(アキヅキ イワオ)

秋月ソリューション事務所 秋月巌ソフトウェア開発者、及び、テクニカルライター執筆記事一覧秋月ソリューション事務所Webサイト

※プロフィールは、執筆時点、または直近の記事の寄稿時点での内容です

この記事は参考になりましたか?

この記事をシェア

CodeZine(コードジン)
https://codezine.jp/article/detail/5598 2010/12/14 16:46

イベント

CodeZine編集部では、現場で活躍するデベロッパーをスターにするためのカンファレンス「Developers Summit」や、エンジニアの生きざまをブーストするためのイベント「Developers Boost」など、さまざまなカンファレンスを企画・運営しています。

新規会員登録無料のご案内

  • ・全ての過去記事が閲覧できます
  • ・会員限定メルマガを受信できます

メールバックナンバー