Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
brendanmc25
Posts: 63
Registered: ‎08-07-2009
My Device: Not Specified

RMS recordStore won't delete

Hi all,

 

I am really stumped with this and am getting desperate - i have just watched about six hours fly by trying to solve this myself

 

I have an app which makes use of rms - problem is when i try to delete a specific recordstore. If i try to delete a diferent recordstore it deletes but if i delete the "name" recordstore i get recordStoreException: name which is not telling me anything. I have tried close in a while loop and then a open that recordstore and then close it to be sure but still i get the exception.

 

Please can someone suggest something - this happens on both emulater and bb, I have tried resets and deleting the app so that the rms files are deleted on uninstallation and this sems to delete them but when i callinstall and call this method it throws the recordStoreException which in the documentation is a general rms error.

 

public static void delete() { try { while(true) { recordStore.closeRecordStore(); Log.info("Closed one"); } } catch(RecordStoreException e) { Log.info("error at close all while " + e); } try { recordStore = RecordStore.openRecordStore( "name", false); recordStore.closeRecordStore(); Log.info("in between delete"); // iu = recordStore.getNumRecords(); String name2 = "name"; RecordStore.deleteRecordStore(name2); } catch(Exception ff) { Log.info("Error deleting" + ff.getMessage() + ff.toString()); } finally { try { recordStore.closeRecordStore(); } catch(Exception tt) { Log.info("error trying to close recordstore " + tt); } } }

 

Please use plain text.
Developer
kumaresan
Posts: 183
Registered: ‎12-17-2008
My Device: 8320

Re: RMS recordStore won't delete

Hi brend,

 

You can use following code for open ,close,deleteall ,delete(particular):

 

 

  public boolean openDataBase()
    {
        try
        {
            rstore = RecordStore.openRecordStore(DB,false);
            return true;
        }
        catch(Exception e)
        {
            Logger.getInstance().Log(LogLevel.EXCEPTION, ": " + e.getMessage());
            return false;
        }
                           
    }

 


    public boolean closeDataBase(String db)
    {
        try
        {
            rstore.closeRecordStore();
            return true;
        }
        catch(Exception e)
        {
            Logger.getInstance().Log(LogLevel.EXCEPTION, ": " + e.getMessage());
            return false;
        }   
    }

 

 

public void deleteDataBase()
    {
  try
        {
            if(openDataBase())
            {
                renum=rstore.enumerateRecords(null,null,false);
                int id=renum.nextRecordId();
                while(renum.hasNextElement())
                {
                    rstore.deleteRecord(id);
                    id=renum.nextRecordId();
                }       
                    rstore.deleteRecord(id);
                 closeDataBase(DB);  
                   
            }
           
        }
        catch(Exception e)
        {
            closeDataBase(DB);
            Logger.getInstance().Log(LogLevel.EXCEPTION, ": " + e.getMessage());
        }
    }

 


    public boolean delete(int id)
    {
        try
        {
            if(!openDataBase())
                return false;
            else
                rstore.deleteRecord(id);
        }
        catch(Exception e)
        {
            Logger.getInstance().Log(LogLevel.EXCEPTION, ": " + e.getMessage());
            return false;           
        }
        closeDataBase(DB);
        return true;               
    }

kums

******************************

Press kudos which the post help you
Please mark posts as solved if you got a solution
Please use plain text.
New Developer
Xpedium
Posts: 12
Registered: ‎06-22-2009
My Device: Not Specified

Re: RMS recordStore won't delete

The above code does not work.

 

if I use it to delete the store and re-open it, I can no longer add records to the DataBase.  It acts like it adds them (i.e. doesn't give an exception), but when I go to read them the DataBase is empty.

 

So was there any other solution to this issue as I am having the same problem?

 

Thanks,

Bob

Please use plain text.
Developer
nikhil_shravane2004
Posts: 109
Registered: ‎03-13-2010
My Device: BlackBerry 8520 Curve Smartphone
My Carrier: -

Re: RMS recordStore won't delete

Hi Friends, Finally have you got the solution for this? If yes, please guide me, as I am still having the same problem. I have already posted a question in a seperate thread but not getting solution. I hope you got the solution, so I am waiting for your replies. Best Regards.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: RMS recordStore won't delete

Opening and closing the record store doesn't guarantee it will be closed. The number of times openRecordStore and closeRecordStore are called must balance. Here's one way to guarantee the record store is closed (unless there's another thread messing things up):

 

 

boolean closed = false;
while (!closed) {
    try {
        recordStore.closeRecordStore();
    } catch (RecordStoreNotOpenException e) {
        closed = true;
    } catch (RecordStoreException e) {
Log.info("Something nasty while closing: " + e.toString());
return;
} } try {
RecordStore.deleteRecordStore("name");
} catch (RecordStoreNotFoundException e) {
Log.info("Couldn't find record store \"name\"");
} catch (RecordStoreException e) {
Log.info("Something nasty while deleting: " + e.toString());
}

 

 




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.