Mayuresh Nirhali's Weblog

JavaDB on JavaME platform

Friday May 25, 2007

As the consumer devices get more sophisticated, more complicated applications will run on devices and there will be greater need to manage the application data. The need for running database engine on small devices will thus be very critical.

JavaDB, a cost effective, easy to use, fully featured, pure Java database with a very small footprint (2MB), looks very promising  on small devices. I tried running it on the latest phoneME advanced (JavaME CDC) platform and could not resist the excitement of putting the details together in this blog. The procedure is very straight forward.

Prepare your setup as below, 

1. Get the latest phoneME advanced platform. Currently, it is supported only on Linux-x86 platform.
2. Get the latest JavaDB release.
3. You also need the JDBC Optional package library for CDC platform. It can be built from the source using the step by step instructions.

Now, try following on your linux box,

<CDC_HOME>/bin/cvm -Xbootclasspath/a:<JDBC_OP>/foundation_jdbc.jar 
-cp <JAVADB_HOME>/lib/derby.jar:<JAVADB_HOME>/lib/derbytools.jar
-Dij.dataSource=org.apache.derby.jdbc.EmbeddedSimpleDataSource
-Dij.dataSource.databaseName=sample
-Dij.dataSource.createDatabase=create
org.apache.derby.tools.ij

Note here that the JDBC Op package can also be built along with CDC binaries, as mentioned here. then, Xbootclasspath need not be specifed while running. By default, the CDC build does not include JDBC Op package, hence we include it in our example.

Please note that, JSR 169, The JDBC Optional package does not support java.sql.Driver. So, the 'ij' cannot be used in its typical form to connect to database via a JDBC driver. The connection in this case is established using the JDBC DataSource.

This will bring up the íj prompt. 'ij' provides Command Line Interface to interact with a database using SQL. You may create such connection directly from your ME application using DataSource objects. You can try some simple steps like below to further test this setup.

ij> create table t (id int not null, addr varchar(20));
0 rows inserted/updated/deleted
ij> insert into t values (1, 'PlanetSun');
1 row inserted/updated/deleted
ij> select * from t;
ID         |ADDR                
--------------------------------
1          |PlanetSun           
1 row selected
ij> exit;


Any database that may have been created by desktop Java application can be read/modified on JavaME platform and the same database can be used by the desktop application again. This can be accomplished so easily only with Java-JavaDB combination!

[3] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

[Trackback] John Embretsen of Sun's Java DB team has just posted a thorough wiki page on using Derby on Java ME platforms. He also shows how to test Derby with IBM's J9 and Sun's phoneME implementations. The tips and tricks section...

Posted by Masood Mortazavi's Blog on November 30, 2007 at 11:11 PM IST #

Can you run Derby on any real-world mobile VM?

I mean, it's nice that you got a shrunken DB in a CDC VM on Linux to run (where you could theoretically run Oracle), but who cares if you can't get it to work in any real-world device?

Also, if Derby's performance is what I remember from CloudScape days, how fast is it going to be on a PDA? Slow? Unbearably slow? Abysmally slow?

Posted by Johann on December 10, 2007 at 03:25 AM IST #

You can use OpenBaseMovil, which has an on-device database with a much smaller footprint, runs on real JavaME CLDC (not CDC) devices, is really fast and also Open Source. It uses the MIDP RMS system.
OpenBaseMovil has more than just a relational database engine for Java Micro Edition, but that part of the framework is probably that gets more attention.

Posted by Narciso Cerezo on May 23, 2008 at 09:45 PM IST #

Post a Comment:
  • HTML Syntax: NOT allowed