MIDP Database Programming Using RMS: Jingwu He Csc 3360.

Slides:



Advertisements
Similar presentations
Bruce Scharlau, University of Aberdeen, 2010 Java ME Record Management System Mobile Computing.
Advertisements

Bruce Scharlau, University of Aberdeen, 2012 Data storage options for mobiles Mobile Computing.
SYMBOL TABLES &CODE GENERATION FOR EXECUTABLES. SYMBOL TABLES Compilers that produce an executable (or the representation of an executable in object module.
Java ME persistence made easy! by Thiago Rossato Thiago Moreira.
BA1 RMS - Record Management System BA2 Record Store En Record er et bytearray af vilkårlig størrelse En RecordStore er et antal.
P1PMF Split1 QBASIC. P1PMF Split2QBasic Command Prompt Will launch the emulator DOS operating system? Press Alt + Enter to display the widescreen.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 8 – File Structures.
MIPS Function Continued
Java I/O The Cheat Sheet. Reading and Writing The basic architecture of Java IO is pluggable. The idea is to have some very simple classes do very simple.
Voice Instant Messenger Andrew Miller CS 491B Fall 2006 Professor Sun.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Cosc 4730 Blackberry: Record Store & SQLite. Introduction RecordStore – Comes from JavaME, MIDP 1.0 On some phone who where you may not have a filesystem.
© 2009 Research In Motion Limited Data structures and memory management on mobile devices.
© The McGraw-Hill Companies, 2006 Chapter 17 The Java Collections Framework.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L08 (Chapter 18) Binary I/O.
1.1 CAS CS 460/660 Introduction to Database Systems File Organization Slides from UC Berkeley.
User Datagram Protocol UDP. Remember, UDP is Not reliable; data may be dropped No guarantee of in-order delivery Duplicate data is possible No built-in.
Guide To UNIX Using Linux Third Edition
Lab 2 Data Streams. Lab 2: Data Streams Introduction Reading from an Input Stream Writing to an Output Stream Filter Streams.
Persistent Storage  Record Stores  mini databases – represent data as byte records  Record Management System (RMS) API  Files and Directories  FileConnection.
Detecting Changes  ItemStateListener interface – detect changes in internal state of an Item  new selection made in a ChoiceGroup  adjusted value of.
MySql In Action Step by step method to create your own database.
PHP1-1 PHP & SQL Xingquan (Hill) Zhu
Mobile Applications with Java ME & BlackBerry. Overview Java ME –Networking –Databases Java ME and the BlackBerry –The BlackBerry wireless device –Converting.
A Simple Two-Pass Assembler
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
 The pool rack example could be implemented using a for loop.  It is also possible to write recursive methods that accomplish things that you might.
By Noorez Kassam Welcome to JNI. Why use JNI ? 1. You already have significantly large and tricky code written in another language and you would rather.
The Java Collections Framework (Part 2) By the end of this lecture you should be able to: Use the HashMap class to store objects in a map; Create objects.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
NMED 3850 A Advanced Online Design January 12, 2010 V. Mahadevan.
PROG Mobile Java Application Development PROG Mobile Java Application Development Memory and Memory Issues Data Storage.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Chapter 14 - Designing Data Access Classes1 Chapter 14 Designing Data Access Classes.
BlackBerry Persistent Storage Models Persistent Storage APIs and Record Management System.
1 CS 132 Spring 2008 Chapter 3 Pointers and Array-Based Lists read p
Chapter 7 Database Basics Tables, Records, and Fields 7 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
What have we learned?. What is a database? An organized collection of related data.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 8 CDC andJ2ME Rob Pooley
모바일 자바 프로그래밍 MIDP RMS Ps lab 오민경. MIDP RMS  RMS (Record Management System)  MIDP 에서 정의하는 영속성을 지닌 자체 데이터 저장 공간  Record Store 의 집합으로 구성된 아주 간단한 데이터베이스.
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
Project18’s Communication Drawing Design By: Camilo A. Silva BIOinformatics Summer 2008.
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
PROG Mobile Java Application Development PROG Mobile Java Application Development Data Storage, Continued.
Queues Chapter 5 Queue Definition A queue is an ordered collection of data items such that: –Items can be removed only at one end (the front of the queue)
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Data Structures Arrays and Lists Part 2 More List Operations.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic properties and characteristics of external files ❏ To.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
Chapter 11.  Large amounts of data are often stored in a database—an organized collection of data.  A database management system (DBMS) provides mechanisms.
Recap Resizing the Vector Push_back function Parameters passing Mechanism Primitive Arrays of Constants Multidimensional Arrays The Standard Library string.
The Record Store ( ) Frank Ducrest. The Record Store 2 The Record Store provides persistence of data between MIDlet runs not quite a DBMS API.
ATS Application Programming: Java Programming
Java- I/O, SMS etc N Amanquah.
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Chapter 7 Text Input/Output Objectives
Chapter 13: File Input and Output
Structured Query Language
Developing a Model-View-Controller Component for Joomla Part 3
Suppose I want to add all the even integers from 1 to 100 (inclusive)
CSC 111 Exam 3 Review Fall 2005.
Chapter 7 Database Basics
Presentation transcript:

MIDP Database Programming Using RMS: Jingwu He Csc 3360

Persistent storage is a non-volatile place for storing the state of objects.. If you save objects to persistent storage, their lifetime is longer than the program that created them, and later you can read their state and continue to work with them. MIDP Record Management System (RMS), a persistent storage for MIDlets, develops MIDP database applications. Persistent storage

The MIDP provides a mechanism for MIDlets to persistently store data and retrieve it later. This mechanism is a simple record-oriented database called the Record Management System (RMS). A MIDP database (or a record store) consists of a collection of records that remain persistent after the MIDlet exits. When you invoke the MIDlet again, it can retrieve data from the persistent record store. To use the RMS, import the javax.microedition.rms package Introducing the RMS

Opening a Record Store To open a record store, use the openRecordStore() static method: RecordStore db = RecordStore.openRecordStore("myDBfile", true); The above code creates a new database file named myDBfile. The second parameter, which is set to true, says that if the record store does not exist, create it.

Creating a New Record A record is an array of bytes. You can use the DataInputStream, DataOutputStream, ByteArrayInputStream, and ByteArrayOutputStream classes to pack and unpack data types into and out of the byte arrays. The first record created has an ID of 1 and is the primary key. The second record has the previous ID + 1. Now suppose you have the following string record: FirstName, LastName, Age. To add this record to the record store, use the addRecord() method as follows: ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.writeUTF(record);byte[] b = baos.toByteArray(); db.addRecord(b, 0, b.length);

Reading Data from the Record Store To read a record from the record store, you construct input streams instead of output streams. This is done as follows: ByteArrayInputStream bais = newByteArrayInputStream(record1); DataInputStream dis = newDataInputStream(bais); String in = dis.readUTF();

Deleting a Record from the Record Store To delete a record from the record store, you have to know the record ID for the record to be deleted. To delete the record, use the deleteRecord() method. This method takes an integer as a parameter, which is the record ID of the record to be deleted. There is no method to get the record ID. To work around this, every time you create a new record, add its record ID to a vector like this: Vector recordIDs = new Vector(); int lastID = 1; //Add a record....parameters are missing here db.addRecord(); // Now add the ID to the vector recordIDs.addElement(new Integer(++lastID));

Deleting a Record from the Record Store Now, to delete a record, find the record ID of the record you want to delete: Enumeration IDs = recordIDs.elements(); while(IDs.hasMoreElements()) { int id = ((Integer) IDs.nextElement()).intValue(); //Compare to see if this is the record you want by //invoking compare() which is shown next. //Then call db.deleteRecord(id); }

Comparing my Record with Records in the Record Store To search for the right record to delete, your application must implement the Comparator interface (by providing an implementation to the compare method) to compare two records. The return value indicates the ordering of the two records. For example, suppose you want to compare two strings that you retrieved from two records. Here is a sample implementation: public someClass implements Comparator { public int compare(byte[] record1, byte[] record2) { ByteArrayInputStream bais1 = new ByteArrayInputStream(record1); DataInputStream dis1 = new DataInputStream(bais1); ByteArrayInputStream bais2 = new ByteArrayInputStream(record2); DataInputStream dis2 = new DataInputStream(bais2); String name1 = dis1.readUTF(); String name2 = dis.readUTF(); int num = name1.compareTo(name2); if (num > 0) { return RecordComparator.FOLLOWS; } else if (num < 0) { return recordcomparator.precedes; } else { return recordcomparator.equivalent; }

Closing the Record Store To close the record store, use the closeRecordStore() method.