Sei sulla pagina 1di 5

Prithwi Raj Chakraborty,Alok Kumar Chowdhury,Sujan Chowdhury,Farhana Shirin Chowdhury Int. J. Comp. Tech. Appl.

, Vol 2 (2), 374-378

An Efficient Approach to Access Database in J2ME Applications

Prithwi Raj Chakraborty Alok Kumar Chowdhury


Dept. of Computer Science and Engineering Dept. of Computer Science and Engineering
Premier University Premier University
Chittagong, Bangladesh Chittagong, Bangladesh
stranger.prithwi@gmail.com alokchy04@yahoo.com

Sujan Chowdhury Farhana Shirin Chowdhury


Dept. of Computer Science and Engineering Dept. of Computer Science and Engineering
Chittagong University of Engineering & Premier University
Technology Chittagong, Bangladesh
Chittagong, Bangladesh fshirin2007@gmail.com
sujan_cse_04@yahoo.com

Abstract

Application development for mobile devices has a modular and scalable architecture. It has two primary
been very challenging. Distributed applications for kinds of components—configurations and profiles. A
mobile devices should have uninterrupted data access. configuration defines the minimum set of JVM (Java
Though most of the mobile phones have CLDC Virtual Machine) features and Java class libraries
configuration, Java provides no standard JDBC driver available for a particular category of devices. A
and API for mobile devices with CLDC configuration. configuration typically represents a group of devices
Relational database in J2ME can be used with some with similar processing power and amounts of
currently available DBMSs and frameworks. But still available memory. A profile is a specification that
there are problems like storage limitation, database defines sets of APIs (Application Programming
inconsistency, nonstandard SQL, platform dependency Interfaces) and features and utilizes the underlying
etc. This paper proposes an approach which ensures configuration to provide a complete run-time
continuous database access with shared DBMS for environment for a specific kind of device. The profile
distributed J2ME applications running on CLDC manages the application, user interface, networking
devices. This approach also supports writing standard and I/O.
SQL in J2ME applications. J2ME defines two configurations, the CLDC
(Connected Limited Device Configuration) and the
Keywords: J2ME database access, DBMS for CLDC CDC (Connected Device Configuration). The CLDC
devices, standard SQL in J2ME, shared database is for devices with small amounts of memory and/or
access, distributed mobile application, platform slow processors. The VM (Virtual Machine) used by
supported J2ME application. the CLDC omits some important features. The CDC,
on the other hand, includes a full JVM and a much
larger set of core classes, so it requires more memory
than the CLDC and a faster processor [1]. CLDC
devices consist of very small UI, memory of about 160
1. Introduction KB to 512 KB, 16 to 32 bit processors. CDC devices
consist of large range of UI, 2 to 16 MB memory and
J2ME (Java 2 Micro Edition) is a Java platform 32 bit processors.
from Sun Microsystems that allows programmers to The proposed approach will be focusing on
use the Java programming language and related tools database access by J2ME applications for mobile
to develop programs for small devices with a limited devices. Mobile devices are increasingly used for
processor power and small memory size like mobile database driven tasks such as product inventory
phones, personal digital assistants etc. To support a tracking, sales order entry, and customer relationship
wide variety of device types, J2ME technology adopts management. While developing applications for

374
Prithwi Raj Chakraborty,Alok Kumar Chowdhury,Sujan Chowdhury,Farhana Shirin Chowdhury Int. J. Comp. Tech. Appl., Vol 2 (2), 374-378

mobile devices, some certain limitations like limitation J2ME database access problem, but they are not the
of energy and resources of mobile devices, ultimate solution for our issues.
disconnecting problem, bandwidth asymmetry etc. Generally, J2ME applications store and
should be kept in mind. J2ME applications that run on manipulate data in nonvolatile memory using RMS.
CDC devices are capable of utilizing DBMS RMS is a combinational file system and database
(Database Management System). This DBMS is management system that enables us to store data in
typically located on a remote server; although some columns and rows similar to database tables. Data can
highly configured CDC devices might have the DBMS be inserted, read, searched and sorted by RMS. But the
stored locally on their hard drive [2]. But CLDC problem is that RMS is not a relational database, so
devices are widely used all over the world for both SQL can not be used. Besides, RMS has limited
personal and programming purposes. The fact is that storage capacity [2]. The amount of memory available
J2ME does not provide any optional package for for record-based data storage varies from device to
database access for CLDC devices. Though some device. The MIDP (Mobile Information Device
light-weight DBMSs are available for CLDC devices, Profile) specification requires devices to reserve at
but there also some problems like data limitation, least 8K of non-volatile memory for persistent data
unavailability of standard SQL, improper data caching storage. The specification does not place any limits on
etc. Moreover, a shared, remote server DBMS can be the size of an individual record, but space constraints
accessed by multiple J2ME applications. So, mobile will vary from device to device [3].
devices should be connected to remote server At present, some frameworks and database
somehow while accessing database, otherwise their engines are available to minimize the problem
transactions may cause data inconsistency. If local regarding J2ME database. Floggy is such a
databases in mobile devices are concerned, it is not framework. This framework creates an abstract
possible to access large amount of data because of interface to manage data in the J2ME applications
storage limitation of mobile devices. So, we are through the artifacts of RMS mechanisms. That is,
proposing a newer approach which includes, J2ME developers do not need to deal with the RMS
low level architecture [4]. The problem with Floggy is
• An API for developers to use standard SQL into that it uses RMS to store and manipulate the
their J2ME client applications for CLDC devices. persistence infrastructure of database objects. As RMS
This API will also give access to locally saved has limited data storage capacity, the storage limitation
schema of remote server DBMS through RMS problem still exists with Floggy.
(Record Management System), a J2ME file OpenBaseMovil is another framework for J2ME
system. applications. It works both as database and scripting
• A remote and shared DBMS server with huge engine with a declarative view definition language.
amount of data. The shared DBMS can have The scripting engine in OpenBaseMovil, known as
multiple accesses from different J2ME client OpenBaseMovil-script, provides some facilities like
applications. easy coding, extendable language, faster execution etc.
• A backup SMS application running on the same It uses a language called bmScript which is an object
remote server (where DBMS is located) to keep oriented language [5]. However, OpenBaseMovil has a
connection between mobile applications and big limitation and it is that it does not support standard
remote DBMS alive while the network bandwidth SQL.
communication (internet communication) is Like frameworks there are some DBMSs also for
interrupted. mobile devices. Mimer SQL Mobile is such a DBMS
which can be accessed by multiple uses with full
2. Background transaction support. A Mimer SQL Mobile database
can be accessed by parallel local applications, but also
Issues of the proposed approach are – use of by remote clients. A local Mimer SQL Mobile
standard SQL in J2ME applications, uninterrupted and application may also access remote Mimer SQL
shared remote database access with large amount of databases. Very efficient compression techniques are
data by multiple J2ME client applications and client used for the data stored in database to reduce the
devices will be CLDC devices. There are some storage needs of mobile device up to 60%. The
database management systems as well as frameworks client/server communication in Mimer SQL Mobile
for CLDC devices to access database like Floggy, utilizes standardized network protocols such as
OpenBaseMovil, Mimer SQL Mobile, J2MEMicroDB LAN/WLAN, 3G/GRPS, Bluetooth, serial port [6].
etc. These software and frameworks partially solved Unlike OpenBaseMovil, Mimer SQL Mobile supports
standard SQL. Supported operating system platforms

375
Prithwi Raj Chakraborty,Alok Kumar Chowdhury,Sujan Chowdhury,Farhana Shirin Chowdhury Int. J. Comp. Tech. Appl., Vol 2 (2), 374-378

for Mimer SQL Mobile are Symbian OS (Operating backup J2SE SMS application which does the same
System)-Series 60, Symbian OS-UIQ, Symbian OS- thing as J2EE web application but it works while there
UIQ3, Linux 2.6+, Windows Mobile etc. But Mimer is no internet connectivity and uses GPRS model. On
SQL Mobile does not support Symbian OS-Series 40 the third layer there is the database server which gets
platform which is widely used [7]. data requests from J2EE web application and J2SE
J2MEMicroDB, a database engine for J2ME SMS application and performs required database
devices, is based on a three-tier architecture which operations as well as sends response back to J2EE web
includes a proxy server application, the remote application and J2SE SMS application. The J2ME
database and mobile client. Data access requests go client application is capable of accessing the remote
from mobile client to proxy server application via database through a two way application layer (second
HTTP (Hyper Text Transport Protocol) and proxy layer).
server application uses the JDBC (Java Database
Connection) API to connect to remote databases [8].
Some features of J2MEMicroDB are – it is
lightweight, it presents time efficient database access,
it uses a remote DBMS through a web service, it
implements a relational database on mobile devices, it
also provides a way to store and retrieve database
objects in mobile device [9]. As mentioned,
J2MEMicroDB uses a remote database, so there is no
storage limitation while the client-end J2ME
application is connected to remote DBMS via
network. This engine implements an offline data
access approach by storing a small mirror of remote
server database into mobile device by RMS so that the
offline J2ME application can use that mirror to make
store and manipulate offline data stored locally into
that mobile device. But if the remote database is
shared by multiple J2ME applications, then the locally
stored offline data is no worth because it is not up-to-
date. So, the offline transactions will contradict with
the original database when the offline device becomes
online.
So, though there are some DBMS frameworks and
database engines available for J2ME, they have some Figure 1. Architecture of the system
limitations also. For this reason, a newer and efficient
approach has been proposed. 3.1. J2ME client application

3. System Architecture The proposed approach supports concurrent


access of remote database by multiple J2ME
Proposed system consists of three-layer applications. The J2ME application can access the
architecture. On the first layer there is a J2ME client remote database either through a J2EE web application
application which runs on mobile device. This J2ME or J2SE SMS application. Both the J2EE web
application will communicate with second layer application and J2SE SMS application reside on
application and submit its queries written into standard remote server along with the database. While internet
SQL. On the first layer, there may be more than one connectivity is available, J2ME application uses J2EE
J2ME applications sharing same second layer web application to access database and uses J2SE
applications. On the second layer there are two SMS application while internet connectivity is
applications which run on remote server (the same unavailable.
server where DBMS in running). Among these, one is For communicating with J2EE web application,
J2EE web application which receives query requests our J2ME client application uses HTTP which is
from J2ME application and sends responses back to supported by all MIDP devices. HTTP makes wireless
J2ME application using HTTP while internet applications more portable and standard [10].
connectivity is available. The other application is a For coding purpose, packages like java.io,
javax.microedition.io have been used. A small portion

376
Prithwi Raj Chakraborty,Alok Kumar Chowdhury,Sujan Chowdhury,Farhana Shirin Chowdhury Int. J. Comp. Tech. Appl., Vol 2 (2), 374-378

of J2ME code is shown which has been used to send The MessageConnection is class factory for
and receive data with HTTP. messages. The setPayloadData() method the payload
data of this message.
conn = (HttpConnection) The portion of codes in above figure shows the
Connector.open(webAppURL); way to send queries via SMS. After sending queries
conn.setRequestProperty(“Content-Type”,“//text the J2ME client application will have to receive back
plain”); ………………………………………………… the response from server via another SMS. For this
byte sendingQuery[] = queryString;
outputstream.write(sendingQuery);
purpose, Push Registry has been used. Push Registry
outputstream.flush(); ……………………………………………… is a welcome addition since MIDP 2.0. The Push
int resp = inputStram.read(); Registry enables MIDlets to set themselves up to be
While((resp)!=-1) launched automatically, without user initiation. The
{ Push Registry manages network and timer initiated
responseString = responseString + (char) resp; MIDlet activation; that is, it enables an inbound
} network connection or a timer-based alarm to wake a
MIDlet up [11]. With Push Registry a port number
(ex: 5550) can be specified for the specific J2ME
Figure 2. A portion of J2ME code to communicate client application. If any SMS comes to that port, it
with J2EE web application automatically received by the J2ME client application.
Port number “0” is not used because if a SMS comes
The Connector.open() method opens a connection. for port “0”, it goes to Inbox of SIM card, without
The setRequestProperty() method sets the general notifying the J2ME client application.
request property for the open connection. Besides all these, the proposed approach uses an
OutputStream class defines interfaces for writing data API to save information about basic schema (database
to an open connection. The write() method writes table structure) like table name, column name etc. of
multiple bytes of data to the open connection. remote database by RMS at J2ME client application.
InputStream class defines interfaces for reading data The javax.microedition.rms package as well as the
from an open connection. The read() method returns a classes like RecordStore, RecordEnumeration etc. has
byte of data as an integer form. been used for this purpose.
J2ME application follows the above process while
internet connectivity is on. But the proposed approach
follows a backup way to access remote database while
3.2. J2EE web application
there is no internet connectivity. For this purposes,
J2ME application follows WMA (Wireless Messaging After receiving queries from J2ME client
API). WMA is built on top of CLDC (or CDC) and application, our J2EE web application uses JDBC
requires only the Generic Connection Framework of driver and JDBC API to process those queries
CLDC 1.0 and CLDC 1.1 devices [3]. The package accessing the database. After processing queries, J2EE
javax.wireless.messaging has been used. A portion of web application sends back a response containing data
J2ME code is shown bellow which has been used to to J2ME client application. The package java.sql has
send SMS. been used. Some used classes are Statement, Resultset,
Connection, DriverManager, DataRequest etc. The
MessageConnection conn; J2EE web application is built on JSP (Java Server
conn = (MessageConnection) Page), Servlet etc.
Connector.open("sms://”+number+“:”+port);
TextMessage tmsg; 3.3. J2SE SMS application
tmsg = (TextMessage)
conn.newMessage(MessageConnection.TEXT_MES
SAGE); Like J2EE web application, J2SE SMS
tmsg.setPayloadText(queryString); application runs on same remote server. It is basically
conn.send(); a console application which uses a GPRS modem
connected to the remote server where the SMS sent
from J2ME client application are stored. J2SE SMS
Figure 3. A portion of J2ME code to send query application always reads the port where modem is
via SMS connected. If it reads any new data (a new SMS), it
parses the SMS data and gets the queries from that
SMS. Then the application uses standard JDBC driver
to access database based upon those queries. After

377
Prithwi Raj Chakraborty,Alok Kumar Chowdhury,Sujan Chowdhury,Farhana Shirin Chowdhury Int. J. Comp. Tech. Appl., Vol 2 (2), 374-378

query execution, J2SE SMS application sends back


response data back to J2ME client application via a 5. Conclusion
SMS through the GPRS modem. At coding level we
use Java Communication API. The used packages are
javax.comm.CommPort,javax.comm.CommPortIdentif J2ME database access has been a very important
ier,jvax.comm.SerialPort etc. A portion of J2SE code topic for the J2ME application developers. The
of SMS application is shown bellow. proposed approach deals with some major points in
J2ME database access. The proposed approach will
CommPort thePort; help J2ME developers to use database for their J2ME
CommPortIdentifier thePortID; applications as well as to make distributed mobile
………………………………………………… applications with J2ME which will have a great impact
thePort = thePortID.open(strPortName, on business perspective also. This proposed approach
TIMEOUTSECONDS * 1000); can be further updated with more features regarding
SerialPort myPort = (SerialPort) thePort; J2ME database access.
………………………………………………………
is = new BufferedReader(new
InputStreamReader(thePort.getInputStream())); 6. References

[1] J2ME Core Concepts. [Online]. Available at:


Figure 4. A portion of J2SE code to read comm http://www.developer.com/java/j2me/article.php/1378971
port data
[2] James Keogh, J2ME: The Complete Reference, Tata
McGraw-Hill Publishing Company Limited, New Delhi,
CommPort is an abstract class that describes a 2003.
communications port made available by the underlying
system. CommPortIdentifier is the central class for [3] Sing Li, and Jonathan Knudsen, Beginning J2ME: From
controlling access to communications ports. SerialPort Novice to Professional, Apress, New Delhi, 2006.
is a RS-232 serial communications port. It describes
the low-level interface to a serial communications port [4] Floggy. [Online]. Available at:
made available by the underlying system. http://floggy.sourceforge.net/index.html

[5] OpenBaseMovil. [Online]. Available at:


4. Discussion http://www.openbasemovil.org/about/

As database based mobile device applications are [6] Mimer SQL Mobile – Highlights. [Online]. Available at:
http://developer.mimer.com/features/feature_18.htm
being used in several personal and business
perspectives, database access in mobile device is a [7] Mimer SQL Products & Platforms. [Online]. Available
handsome issue for the mobile application developers at: http://developer.mimer.com/platforms/index.tml
now. Though there are several programming
languages and platforms for mobile device application [8] Marc Alier, Pablo Casado, and Maria José Casany,
developments, J2ME is widely used because it is “J2MEMicroDB: An Open Source Distributed database
platform independent (J2ME application can be run on Engine for Mobile Applications”, Proceedings of the 5th
any Java enabled mobile devices), open source, easily international symposium on Principles and practice of
used etc. These reasons drag the focus towards J2ME programming in Java, ACM New York, Lisboa, Portugal,
September 5-7, 2007, Volume: 272, pp. 231-235.
database access. The proposed approach gives solution
to all of the discussed issues. With this approach, [9] Marc Alier, Pablo Casado, and Maria José Casany,
standard SQL command can be used into J2ME “J2MEMicroDB: a new Open Source lightweight database
application dealing with a large amount of data. This engine for J2ME mobile devices”, Journal of Intelligent
approach supports use of multiple J2ME applications. Manufacturing, Springer, Heidelberg, 2009, Volume: 20,
The approach includes a backup way to access Issue: 3, pp. 303-309.
database while there is no internet connectivity. The
proposed approach also supports CLDC devices with [10] Yu Feng, and Dr. Jun Zhu, Wireless Java Programming
Series 40 (or upper) platform(s). This approach is with J2ME, Sams Publishing, New Delhi, 2001.
tested with several mobile hand sets like – Nokia 3110
[11] The MIDP 2.0 Push Registry. [Online]. Available at:
classic, Nokia 2730 classic, Nokia 3720 classic, Nokia http://developers.sun.com/mobility/midp/articles/pushreg/
2700 classic, Nokia E52, Nokia E71 etc. with
satisfactory performances.

378

Potrebbero piacerti anche