Results 1 to 3 of 3
  1. #1
    JavaJunkie is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default Store data is not retrieving

    Hi,

    I'm stuck in the problem of retrieving the stored data in midlet. Whenever I try to retrieve the data I'm getting the following exception:
    Java Code:
    java.lang.ArrayIndexOutOfBoundsException
    	at javax.microedition.rms.RecordStore.getRecordIDs(+61)
    	at javax.microedition.rms.RecordEnumerationImpl.rebuild(+21)
    	at javax.microedition.rms.RecordEnumerationImpl.<init>(+41)
    	at javax.microedition.rms.RecordStore.enumerateRecords(+15)
    	at recordStore.dis1(+34)
    	at Project.commandAction(+313)
    	at javax.microedition.lcdui.List.callKeyPressed(+80)
    	at javax.microedition.lcdui.Display$DisplayAccessor.keyEvent(+198)
    	at javax.microedition.lcdui.Display$DisplayManagerImpl.keyEvent(+11)
    	at com.sun.midp.lcdui.DefaultEventHandler.keyEvent(+127)
    	at com.sun.midp.lcdui.AutomatedEventHandler.keyEvent(+210)
    	at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+114)
    	at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
    The code which I've used in storing the data is:

    Java Code:
    ByteArrayOutputStream stream=new ByteArrayOutputStream();
    DataOutputStream writer=new DataOutputStream(stream);
      writer.writeUTF(t.getString());// t and t1 here is a reference of TextField type
      writer.writeUTF(t1.getString());
      
    
        byte[] b=stream.toByteArray();
                          
    	byte[] b1=stream.toByteArray();
    	  rs.addRecord(b,0,b.length);
    	  rs.addRecord(b1,0,b1.length);

    and the code which I've used for retrieving the stored data is:

    ByteArrayInputStream stream;
    DataInputStream reader;


    Java Code:
    RecordEnumeration en=rs.enumerateRecords(null,null,false);
     int id=en.nextRecordId();
    
    
     while(en.hasNextElement())
     {
    
    byte[] rec=new byte[rs.getRecordSize(id)];
    rec=rs.getRecord(id);
    stream=new ByteArrayInputStream(rec);
    reader=new DataInputStream(stream);
    System.out.println(reader.readUTF());

    Thanks in advance.
    Last edited by JavaJunkie; 05-05-2009 at 08:04 AM.

  2. #2
    JavaJunkie is offline Member
    Join Date
    Apr 2009
    Posts
    12
    Rep Power
    0

    Default

    Please reply. I'm still having trouble in solving this problem.:confused:

  3. #3
    gopicsq is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default RecordStore

    table="login"

    openRecStore();

    if (ns == 0) {
    writeRecord("dileepp");
    writeRecord("1207sp");
    writeRecord("000002");
    writeRecord("True");
    writeRecord("True");

    }

    public void openRecStore(){
    try{ rs = RecordStore.openRecordStore(table,true );
    }catch (Exception e){}
    }



    public void writeRecord(String str){
    byte[] rec = str.getBytes();
    try{rs.addRecord(rec, 0, rec.length);
    }catch (Exception e){}
    }




    public void readRecords(){


    int ln=0;
    mdes = new String[ln];

    String[] sArry;
    try{
    ln = rs.getNumRecords();
    }catch (Exception e){}

    mdes = new String[ln];

    int x=0;
    try{
    byte[] recData = new byte[rs.getNumRecords()];
    int len;
    for(int i = 1; i <= rs.getNumRecords(); i++){
    recData = new byte[rs.getRecordSize(i)];
    len = rs.getRecord(i, recData, 0);
    String des = new String(recData, 0, len);
    mdes[i] = des ;

    }




    } // for loop



    }catch (Exception e){}


    if ( ln == 0) {
    Alert error = new Alert ("Status","No Record found in "+table+ " Table",null, AlertType.INFO );
    error.setTimeout(Alert.FOREVER);
    }



    }



    Regards

    Gopinath

Similar Threads

  1. help me to store data in a class
    By neeraj.singh in forum New To Java
    Replies: 2
    Last Post: 08-06-2009, 08:31 AM
  2. how to store the data in data base
    By eclipse3.4ide in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 04:25 AM
  3. Replies: 1
    Last Post: 12-28-2008, 10:25 AM
  4. error while retrieving data from data base
    By kirtesh4u in forum New To Java
    Replies: 5
    Last Post: 11-15-2008, 04:10 PM
  5. Retrieving data from the DB
    By yuchuang in forum JDBC
    Replies: 2
    Last Post: 11-27-2007, 08:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •