Building the Android JDBC Driver

本文档详细介绍了如何为Android平台构建并使用BerkeleyDB (BDB) JDBC驱动的过程,包括所需的Android SDK与NDK安装、BerkeleyDB包的下载与配置、JDBC库的构建步骤及如何在Eclipse中进行测试验证。

http://blog.sina.com.cn/s/blog_4c5a84ac010162xo.html

This section describes how to build and use the BDB JDBC driver for Android. Note that the BDB JDBC driver cannot currently be built on a Windows platform.

  1. Download and install the Android SDK. The installation instructions can be found here:

    http://developer.android.com/sdk/installing.html

  2. Download and install the Android NDK. It can be found here:

    http://developer.android.com/sdk/ndk/index.html

  3. Build the BDB JDBC libraries.

    1. If you do not already have it, download the Berkeley DB package from here:

      http://www.oracle.com/technetwork/database/berkeleydb/downloads/index.html

      Note that you must be using a 5.3.x or higher version of the product in order for these instructions to work. Once you have the package, unpack it:

      $ tar zxvf db-x.y.z.tar.gz $ cd db-x.y.z

      Where x.y.z the major, minor, and point release version of the Berkeley DB distribution which you are using.

      Also, note that in the following instructions, the directory denoted by db-x.y.z, above, is referred to as .

    2. Build an x86/x64 JDBC package. This is required because the building process will generate target files which are required to build Android NDK. Also, the built JAR file can be imported by eclipse, which will then convert it to the Android Dalvik JAR format.

      To do this, edit /lang/sql/jdbc/SQLit/Database.java and replace all instances of System.loadLibrary("sqlite_jni") with System.loadLibrary("oracle-jdbc").

      Once you have done this, configure and make the library. The following example shows the minimum configuration options that you need to use in order to configure the Berkeley DB JDBC driver. For your particular installation, other configuration options might be interesting to you. See Configuring Berkeley DB and Android Configuration Options for more information.

      cd /build_unix ../dist/configure --enable-jdbc && make
  4. Build the Android NDK:

    $ cd /build_android/jdbc/jni $ /ndk-build

    This results in the following required files:

    /build_android/jdbc/libs/armeabi/liboracle-jdbc.so
    /build_android/jdbc/libs/armeabi/dbsql
    /build_unix/jdbc/sqlite.jar

Having built the JDBC driver, you can now use it with your project. You can do this using Eclipse and the ADT plugin, which you can get from here:

http://developer.android.com/sdk/eclipse-adt.html

To make sure everything is working:

  1. Start Eclipse and create an Android project. Use:

    • test_jdbc as the Android project name.

    • Create it as an Android 3.2 project.

    • For the package name, use example.jdbc.

  2. This results in an empty code file. Copy and paste the following example code into that file:

    package example.testjdbc; import SQLite.*; import java.io.*; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import java.sql.*; public class Test_jdbcActivity extends Activity { 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
  3. Copy the following files into place:

    $ cd /test_jdbc $ mkdir -p libs/armeabi $ cp -r /build_android/jdbc/libs/armeabi/liboracle-jdbc.so \ libs/armeabi $ cp -r /build_unix/jdbc/sqlite.jar libs
  4. Back in Eclipse, right click the project name, and select the refresh option to reload the project from the directory. The two new files that were copied into place in the previous step are now included in the project view.

  5. Convert the JAR file to the Android Dalvik format:

    1. Right-click on your project.

    2. Choose Build Path -> Configure Build Path

    3. Click the Libraries tab.

    4. Click Add JARS.

  6. Run the project:

    1. Choose Property -> Android and select any one of the usable build targets.

    2. Right click the project. Choose Run As -> Android

  7. Verify your installation. After a short pause (depending on the speed of your system), the application logo is displayed. Use the Android adb command line application to make sure the application is running as expected:

    $ cd /platform-tools $ ./adb logcat I/System.out( 539): Appstart: I/System.out( 539): Coffee Break Coffees and Prices: I/System.out( 539): Colombian 7.99 I/System.out( 539): French_Roast 8.99 I/System.out( 539): Espresso 9.99 I/System.out( 539): Colombian_Decaf 8.99 I/System.out( 539): French_Roast_Decaf 9.99

    You can also check if the database (example.db) exists in the emulator:

    $ ./adb shell ls /data/data/example.testjdbc example.db example.db-journal lib

    Finally, check the database using the BDB SQL shell:

    $ ./adb push /build_android/jdbc/libs/armeabi/dbsql \ /data/data/example.testjdbc 326 KB/s (1293760 bytes in 3.865s) $ ./adb shell root@android:/ # cd /data/data/example.testjdbc root@android:/data/data/example.testjdbc # ./dbsql example.db Berkeley DB 11g Release 2, library version 11.2.5.2.36 Enter ".help" for instructions Enter SQL statements terminated with a ";" dbsql> .tables COFFEES dbsql> select * from COFFEES; Colombian|101|7.99|0|0 French_Roast|49|8.99|0|0 Espresso|150|9.99|0|0 Colombian_Decaf|101|8.99|0|0 French_Roast_Decaf|49|9.99|0|0 dbsql> .quit

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值