0 Replies Latest reply: Feb 3, 2010 4:19 AM by 843851 RSS

    Database storage -Record Management System- problems using J2ME for voting

    843851
      Hi..

      I am now on a project to develop an application for mobile devices. My project is “Java based e-voting system through Bluetooth (Mobile-to-Mobile)”. So, I am fully utilized the J2ME and the Bluetooth technology. As for Bluetooth technology, I need at least one Server and several Clients in order to make my program works. For this project, both Server and Clients are using mobile devices.

      Currently, I'm facing some problems that involved the database itself. I'm using the RMS (Record Management System) for the database storage. My problems are:

      1)As Client send data to the Server through the Bluetooth connection, all previous data in the Sever are gone and being replaced with the new data that is being sent. As I'm developing a voting system, I need my Server to update the data when Client sent the data, not replacing the data. How I can do that? I don’t want to lost all the previous data in the Server.

      2)As I am using mobile phones for both Server and Client, I realized that there are limited tasks that mobile phones can do. So, I just wondering, is it possible for me to make all the database of my Client visible to Server? (eg. of database: voters' name, voters' voting, etc..)

      Below is 1 class that liases with the RMS of my project.
      Really needs helps from others.

      Thank you.
      /**
       * 
       * This class handles all the work involving RecordStore
       *
       */
      import javax.microedition.rms.*;
      
      public class RecordInterface
      {
           private RecordStore record;
           private String recordName;
           
           //********** STANDARD METHODS **********//
           public RecordInterface(RecordStore rs, String rn)
           {
                record = rs;
                recordName = rn;
           }
           
           //********** NON-STANDARD METHODS **********//
           //get record (two versions - with parameter, w/o parameter (gets the first record by default) - DONE
           //get all records - CANCEL, I don't want to return an array of arrays
           //get number of records - DONE
           //append records - DONE
           //replace records - DONE
           //reset records
           public void Add(byte[] input)
           {
                try {
                     //System.out.println("####Method invoked, size of byte is: " + input.length);
                     OpenRecord();               
                     record.addRecord(input, 0, input.length);
                     CloseRecord();
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - Get()"); }
           }
           
           public byte[] Get()
           {
                byte[] result = null;
                OpenRecord();
                try {
                     result = record.getRecord(1);
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - Get()"); }
                
                CloseRecord();
                return (result);
           }
           public byte[] Get(int index)
           {
                byte[] result = null;
                OpenRecord();
                try {
                     result = record.getRecord(index);
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - Get(int)"); }
                
                CloseRecord();
                return (result);
           }
           
           public int GetQty()
           {
                int result = 0;
                try {
                     OpenRecord();
                     result = record.getNumRecords();          
                     CloseRecord();
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - GetQty"); }
                return (result);
           }
           
           public void Set(int index, byte[] input)
           {
                try {
                     OpenRecord();
                     record.setRecord(index, input, 0, input.length);
                     CloseRecord();
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - Get()"); }
           }
           
           //********** internal - open and close records **********
           private void CloseRecord()
           {
                try {
                     record.closeRecordStore();               
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - CloseRecord()"); }
           }
           private void OpenRecord()
           {
                try {
                     record = RecordStore.openRecordStore(recordName, true);
                } catch (RecordStoreException r) { System.err.println("Error in RecordInterface - OpenRecord()"); }
           }     
      }