Using the RDM JDBC Driver on Android

This section describes how to use the RDM JDBC driver for Android.

Having downloaded the RDM Android package, you can now use it with your project. You can do this using Eclipse and the ADT plug-in, which you can get from here:

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

With the steps above completed you should be able to begin developing applications using the RDM Database on Android.

The following steps will demonstrate using the RDM JDBC driver for Android with a simple example.

Eclipse + ADT plug-in

  1. Create a workspace inside the Eclipse IDE.
  2. Create a Android Application Project using:
    1. rdmTest as the project name.
    2. Use example.rdm.rdmjdbc as the package name
    3. Using API 18 as the Target SDK (note – minimum required SDK for the RDM JDBC driver is API 10: Android 2.3.3 (Gingerbread)

  1. The wizard generates a blank Activity, then just copy and past the following example code into that file
package example.rdm.rdmjdbc;

import java.sql.*;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;

public class RDM_TestActivity extends Activity {

	private static final String TAG = "RDMTest";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_rdm__test);
		
		Log.v(TAG, "Test: RDM JDBC driver for Android");
		
		Connection conn;
		Statement stmt;
		ResultSet rs;
		
		String dbUrl = "jdbc:raima:rdm://local?appname=example.rdm.rdmjdbc";
		
		try {
			Class.forName("com.raima.rdm.jdbc.RDMDriver");
		} catch (ClassNotFoundException cfe)
		{
			Log.v(TAG, cfe.getMessage());
		}
		
		try {
			conn = DriverManager.getConnection(dbUrl);
			conn.setAutoCommit(false);
			stmt = conn.createStatement();
			stmt.executeUpdate("DROP DATABASE IF EXISTS CONTACTS");
			stmt.executeUpdate("CREATE DATABASE CONTACTS");
			stmt.executeUpdate("CREATE TABLE PERSON (" +
							   "    PERSONID int, " +
					           "     LASTNAME  varchar(255), " + 
							   "     FIRSTNAME varchar(255), " + 
					           "     ADDRESS   varchar(255), " + 
					           "     CITY      varchar(255));");
			conn.commit();
			stmt.close();
			stmt = conn.createStatement();
			stmt.execute("INSERT INTO PERSON " + 
						 "values(1, 'SMITH', 'JOE', '101 Main Street', 'Mayberry')");
			stmt.execute("INSERT INTO PERSON " +
						 "values(2, 'SMITH', 'JANE', '101 Main Street', 'Mayberry')");
			conn.commit();
			rs = stmt.executeQuery("SELECT FIRSTNAME, LASTNAME from PERSON");
			while (rs.next()) {
				Log.v(TAG, rs.getString(1) + " " + rs.getString(2));
			}
			rs.close();
			stmt.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			Log.v(TAG, e.getMessage());
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.rdm__test, menu);
		return true;
	}

}
  1. Copy the following files into the project workspace directory libs/armeabi
    1. librdmbase-15.so
    2. librdmddl-15.so
    3. librdmenc-15.so
    4. librdmha-15.so
    5. librdmhttp-15.so
    6. libjdbcjni-15.so
    7. librdmpsp-15.so
    8. librdmrdm-15.so
    9. librdmrsql-15.so
    10. librdmsbase-15.so
    11. librdmtfs-15.so
    12. librdmtransport-15.so
    13. librdmxml-15.so
  2. Copy rdmjdbc-15.jar into the project workspace directory libs
  3. Convert the rdmjdbc-15.jar to the Android Dalvik format
    1. From Project Properties
    2. Choose Build Path => Configure Build Path
    3. Select the Libraries tab
    1. Click on Add JARs, and select the rdmjdbc-15.jar in the libs directory.

  1. Run the Project via Run As -> Android Application
  2. This simple example app captures database query results to the Android log, so verify this simple test with the Android adb view in Eclipse.