mobile devices should have uninterrupted data access. Though most of the
mobile .... RMS is a combinational file system and database management system
that ..... tested with several mobile hand sets like – Nokia 3110 classic, Nokia
2730 ...
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 Dept. of Computer Science and Engineering Premier University Chittagong, Bangladesh
[email protected]
Alok Kumar Chowdhury Dept. of Computer Science and Engineering Premier University Chittagong, Bangladesh
[email protected]
Sujan Chowdhury Dept. of Computer Science and Engineering Chittagong University of Engineering & Technology Chittagong, Bangladesh
[email protected]
Farhana Shirin Chowdhury Dept. of Computer Science and Engineering Premier University Chittagong, Bangladesh
[email protected]
Abstract Application development for mobile devices has been very challenging. Distributed applications for mobile devices should have uninterrupted data access. Though most of the mobile phones have CLDC configuration, Java provides no standard JDBC driver and API for mobile devices with CLDC configuration. Relational database in J2ME can be used with some currently available DBMSs and frameworks. But still there are problems like storage limitation, database inconsistency, nonstandard SQL, platform dependency etc. This paper proposes an approach which ensures continuous database access with shared DBMS for distributed J2ME applications running on CLDC devices. This approach also supports writing standard SQL in J2ME applications. Keywords: J2ME database access, DBMS for CLDC devices, standard SQL in J2ME, shared database access, distributed mobile application, platform supported J2ME application.
1. Introduction J2ME (Java 2 Micro Edition) is a Java platform from Sun Microsystems that allows programmers to use the Java programming language and related tools to develop programs for small devices with a limited processor power and small memory size like mobile phones, personal digital assistants etc. To support a wide variety of device types, J2ME technology adopts
a modular and scalable architecture. It has two primary kinds of components—configurations and profiles. A configuration defines the minimum set of JVM (Java Virtual Machine) features and Java class libraries available for a particular category of devices. A configuration typically represents a group of devices with similar processing power and amounts of available memory. A profile is a specification that defines sets of APIs (Application Programming Interfaces) and features and utilizes the underlying configuration to provide a complete run-time environment for a specific kind of device. The profile manages the application, user interface, networking and I/O. J2ME defines two configurations, the CLDC (Connected Limited Device Configuration) and the CDC (Connected Device Configuration). The CLDC is for devices with small amounts of memory and/or slow processors. The VM (Virtual Machine) used by 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 KB to 512 KB, 16 to 32 bit processors. CDC devices consist of large range of UI, 2 to 16 MB memory and 32 bit processors. The proposed approach will be focusing on database access by J2ME applications for mobile devices. Mobile devices are increasingly used for database driven tasks such as product inventory tracking, sales order entry, and customer relationship 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 of energy and resources of mobile devices, disconnecting problem, bandwidth asymmetry etc. should be kept in mind. J2ME applications that run on CDC devices are capable of utilizing DBMS (Database Management System). This DBMS is typically located on a remote server; although some highly configured CDC devices might have the DBMS stored locally on their hard drive [2]. But CLDC devices are widely used all over the world for both personal and programming purposes. The fact is that J2ME does not provide any optional package for database access for CLDC devices. Though some light-weight DBMSs are available for CLDC devices, but there also some problems like data limitation, unavailability of standard SQL, improper data caching etc. Moreover, a shared, remote server DBMS can be accessed by multiple J2ME applications. So, mobile devices should be connected to remote server somehow while accessing database, otherwise their transactions may cause data inconsistency. If local databases in mobile devices are concerned, it is not possible to access large amount of data because of storage limitation of mobile devices. So, we are proposing a newer approach which includes, •
•
•
An API for developers to use standard SQL into their J2ME client applications for CLDC devices. This API will also give access to locally saved schema of remote server DBMS through RMS (Record Management System), a J2ME file system. A remote and shared DBMS server with huge amount of data. The shared DBMS can have multiple accesses from different J2ME client applications. A backup SMS application running on the same remote server (where DBMS is located) to keep connection between mobile applications and remote DBMS alive while the network bandwidth communication (internet communication) is interrupted.
2. Background Issues of the proposed approach are – use of standard SQL in J2ME applications, uninterrupted and shared remote database access with large amount of data by multiple J2ME client applications and client devices will be CLDC devices. There are some database management systems as well as frameworks for CLDC devices to access database like Floggy, OpenBaseMovil, Mimer SQL Mobile, J2MEMicroDB etc. These software and frameworks partially solved
J2ME database access problem, but they are not the ultimate solution for our issues. Generally, J2ME applications store and manipulate data in nonvolatile memory using RMS. RMS is a combinational file system and database management system that enables us to store data in columns and rows similar to database tables. Data can be inserted, read, searched and sorted by RMS. But the problem is that RMS is not a relational database, so SQL can not be used. Besides, RMS has limited storage capacity [2]. The amount of memory available for record-based data storage varies from device to device. The MIDP (Mobile Information Device Profile) specification requires devices to reserve at least 8K of non-volatile memory for persistent data storage. The specification does not place any limits on the size of an individual record, but space constraints will vary from device to device [3]. At present, some frameworks and database engines are available to minimize the problem regarding J2ME database. Floggy is such a framework. This framework creates an abstract interface to manage data in the J2ME applications through the artifacts of RMS mechanisms. That is, J2ME developers do not need to deal with the RMS low level architecture [4]. The problem with Floggy is that it uses RMS to store and manipulate the persistence infrastructure of database objects. As RMS has limited data storage capacity, the storage limitation problem still exists with Floggy. OpenBaseMovil is another framework for J2ME applications. It works both as database and scripting engine with a declarative view definition language. The scripting engine in OpenBaseMovil, known as OpenBaseMovil-script, provides some facilities like easy coding, extendable language, faster execution etc. It uses a language called bmScript which is an object oriented language [5]. However, OpenBaseMovil has a big limitation and it is that it does not support standard SQL. Like frameworks there are some DBMSs also for mobile devices. Mimer SQL Mobile is such a DBMS which can be accessed by multiple uses with full transaction support. A Mimer SQL Mobile database can be accessed by parallel local applications, but also by remote clients. A local Mimer SQL Mobile application may also access remote Mimer SQL databases. Very efficient compression techniques are used for the data stored in database to reduce the storage needs of mobile device up to 60%. The client/server communication in Mimer SQL Mobile utilizes standardized network protocols such as LAN/WLAN, 3G/GRPS, Bluetooth, serial port [6]. 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 System)-Series 60, Symbian OS-UIQ, Symbian OSUIQ3, Linux 2.6+, Windows Mobile etc. But Mimer SQL Mobile does not support Symbian OS-Series 40 platform which is widely used [7]. J2MEMicroDB, a database engine for J2ME devices, is based on a three-tier architecture which includes a proxy server application, the remote database and mobile client. Data access requests go from mobile client to proxy server application via HTTP (Hyper Text Transport Protocol) and proxy 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-todate. 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 limitations also. For this reason, a newer and efficient approach has been proposed.
3. System Architecture Proposed system consists of three-layer architecture. On the first layer there is a J2ME client application which runs on mobile device. This J2ME application will communicate with second layer application and submit its queries written into standard SQL. On the first layer, there may be more than one J2ME applications sharing same second layer applications. On the second layer there are two applications which run on remote server (the same server where DBMS in running). Among these, one is J2EE web application which receives query requests from J2ME application and sends responses back to J2ME application using HTTP while internet connectivity is available. The other application is a
backup J2SE SMS application which does the same thing as J2EE web application but it works while there is no internet connectivity and uses GPRS model. On the third layer there is the database server which gets data requests from J2EE web application and J2SE SMS application and performs required database operations as well as sends response back to J2EE web application and J2SE SMS application. The J2ME client application is capable of accessing the remote database through a two way application layer (second layer).
Figure 1. Architecture of the system
3.1. J2ME client application The proposed approach supports concurrent access of remote database by multiple J2ME applications. The J2ME application can access the remote database either through a J2EE web application or J2SE SMS application. Both the J2EE web application and J2SE SMS application reside on remote server along with the database. While internet connectivity is available, J2ME application uses J2EE web application to access database and uses J2SE SMS application while internet connectivity is unavailable. For communicating with J2EE web application, our J2ME client application uses HTTP which is supported by all MIDP devices. HTTP makes wireless applications more portable and standard [10]. 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 and receive data with HTTP. conn = (HttpConnection) Connector.open(webAppURL); conn.setRequestProperty(“Content-Type”,“//text plain”); ………………………………………………… byte sendingQuery[] = queryString; outputstream.write(sendingQuery); outputstream.flush(); ……………………………………………… int resp = inputStram.read(); While((resp)!=-1) { responseString = responseString + (char) resp; }
Figure 2. A portion of J2ME code to communicate with J2EE web application The Connector.open() method opens a connection. The setRequestProperty() method sets the general request property for the open connection. OutputStream class defines interfaces for writing data to an open connection. The write() method writes multiple bytes of data to the open connection. InputStream class defines interfaces for reading data from an open connection. The read() method returns a byte of data as an integer form. J2ME application follows the above process while internet connectivity is on. But the proposed approach follows a backup way to access remote database while there is no internet connectivity. For this purposes, J2ME application follows WMA (Wireless Messaging API). WMA is built on top of CLDC (or CDC) and requires only the Generic Connection Framework of CLDC 1.0 and CLDC 1.1 devices [3]. The package javax.wireless.messaging has been used. A portion of J2ME code is shown bellow which has been used to send SMS. MessageConnection conn; conn = (MessageConnection) Connector.open("sms://”+number+“:”+port); TextMessage tmsg; tmsg = (TextMessage) conn.newMessage(MessageConnection.TEXT_MES SAGE); tmsg.setPayloadText(queryString); conn.send();
Figure 3. A portion of J2ME code to send query via SMS
The MessageConnection is class factory for messages. The setPayloadData() method the payload data of this message. The portion of codes in above figure shows the way to send queries via SMS. After sending queries the J2ME client application will have to receive back the response from server via another SMS. For this purpose, Push Registry has been used. Push Registry is a welcome addition since MIDP 2.0. The Push Registry enables MIDlets to set themselves up to be launched automatically, without user initiation. The Push Registry manages network and timer initiated 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 client application. If any SMS comes to that port, it automatically received by the J2ME client application. Port number “0” is not used because if a SMS comes for port “0”, it goes to Inbox of SIM card, without notifying the J2ME client application. Besides all these, the proposed approach uses an API to save information about basic schema (database table structure) like table name, column name etc. of remote database by RMS at J2ME client application. The javax.microedition.rms package as well as the classes like RecordStore, RecordEnumeration etc. has been used for this purpose.
3.2. J2EE web application After receiving queries from J2ME client application, our J2EE web application uses JDBC driver and JDBC API to process those queries accessing the database. After processing queries, J2EE web application sends back a response containing data to J2ME client application. The package java.sql has been used. Some used classes are Statement, Resultset, Connection, DriverManager, DataRequest etc. The J2EE web application is built on JSP (Java Server Page), Servlet etc.
3.3. J2SE SMS application Like J2EE web application, J2SE SMS application runs on same remote server. It is basically 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 application always reads the port where modem is 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 SMS through the GPRS modem. At coding level we use Java Communication API. The used packages are javax.comm.CommPort,javax.comm.CommPortIdentif ier,jvax.comm.SerialPort etc. A portion of J2SE code of SMS application is shown bellow. CommPort thePort; CommPortIdentifier thePortID; ………………………………………………… thePort = thePortID.open(strPortName, TIMEOUTSECONDS * 1000); SerialPort myPort = (SerialPort) thePort; ……………………………………………………… is = new BufferedReader(new InputStreamReader(thePort.getInputStream()));
Figure 4. A portion of J2SE code to read comm port data CommPort is an abstract class that describes a communications port made available by the underlying system. CommPortIdentifier is the central class for controlling access to communications ports. SerialPort is a RS-232 serial communications port. It describes the low-level interface to a serial communications port made available by the underlying system.
4. Discussion As database based mobile device applications are being used in several personal and business perspectives, database access in mobile device is a handsome issue for the mobile application developers now. Though there are several programming languages and platforms for mobile device application developments, J2ME is widely used because it is platform independent (J2ME application can be run on any Java enabled mobile devices), open source, easily used etc. These reasons drag the focus towards J2ME database access. The proposed approach gives solution to all of the discussed issues. With this approach, standard SQL command can be used into J2ME application dealing with a large amount of data. This approach supports use of multiple J2ME applications. The approach includes a backup way to access database while there is no internet connectivity. The proposed approach also supports CLDC devices with Series 40 (or upper) platform(s). This approach is tested with several mobile hand sets like – Nokia 3110 classic, Nokia 2730 classic, Nokia 3720 classic, Nokia 2700 classic, Nokia E52, Nokia E71 etc. with satisfactory performances.
5. Conclusion J2ME database access has been a very important topic for the J2ME application developers. The proposed approach deals with some major points in J2ME database access. The proposed approach will help J2ME developers to use database for their J2ME applications as well as to make distributed mobile applications with J2ME which will have a great impact on business perspective also. This proposed approach can be further updated with more features regarding J2ME database access.
6. References [1] J2ME Core Concepts. [Online]. Available at: http://www.developer.com/java/j2me/article.php/1378971 [2] James Keogh, J2ME: The Complete Reference, Tata McGraw-Hill Publishing Company Limited, New Delhi, 2003. [3] Sing Li, and Jonathan Knudsen, Beginning J2ME: From Novice to Professional, Apress, New Delhi, 2006. [4] Floggy. [Online]. Available at: http://floggy.sourceforge.net/index.html [5] OpenBaseMovil. [Online]. Available at: http://www.openbasemovil.org/about/ [6] Mimer SQL Mobile – Highlights. [Online]. Available at: http://developer.mimer.com/features/feature_18.htm [7] Mimer SQL Products & Platforms. [Online]. Available at: http://developer.mimer.com/platforms/index.tml [8] Marc Alier, Pablo Casado, and Maria José Casany, “J2MEMicroDB: An Open Source Distributed database Engine for Mobile Applications”, Proceedings of the 5th international symposium on Principles and practice of programming in Java, ACM New York, Lisboa, Portugal, September 5-7, 2007, Volume: 272, pp. 231-235. [9] Marc Alier, Pablo Casado, and Maria José Casany, “J2MEMicroDB: a new Open Source lightweight database engine for J2ME mobile devices”, Journal of Intelligent Manufacturing, Springer, Heidelberg, 2009, Volume: 20, Issue: 3, pp. 303-309. [10] Yu Feng, and Dr. Jun Zhu, Wireless Java Programming with J2ME, Sams Publishing, New Delhi, 2001. [11] The MIDP 2.0 Push Registry. [Online]. Available at: http://developers.sun.com/mobility/midp/articles/pushreg/
378