Hi All
I want to store string in record store and retrieve them again .. I tried to do that many times but the code not work
Can any one help me??
thanks in advance
Hi All
I want to store string in record store and retrieve them again .. I tried to do that many times but the code not work
Can any one help me??
thanks in advance
ITs So simple Convert String in to byte .....then store it in Record Store and get them in byte array and Again covert it into string
String str;
recordStore.addRecord(str.getBytes(), 0,str.getBytes().length);
and u can get this by this methode
String string = new String(record.getRecord(0));
Anshu Chauhan
J2me Developer
Hi,
Follow suggested by ansh...for the task you have to do..
for more operation/information check this link out..
http://www.ibm.com/developerworks/li...e-j2me3-2.html
and
http://www.ibm.com/developerworks/library/j-j2me3/
And a very good example -
http://java.sun.com/developer/J2METe...02/tt0226.html
Thanks,
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
(
I wrote this code right now but not working
I don't know where is the problem
I have a list containing some of string elements
I tried to save these elements one by one by select it from the list and select save command
so I wrote this code inside save command
writeStream and openRecStore() methods as followString __selectedString = getDevicesList().getString(getDevicesList().getSelectedIndex());
try {
openRecStore();
} catch (RecordStoreException ex) {
ex.printStackTrace();
}
writeStream(__selectedString);
and then browse the database , retrieve element from record store by following code
public void openRecStore() throws RecordStoreException
{
// Create record store if it does not exist
rs = RecordStore.openRecordStore(REC_STORE, true);
}
public void writeStream( String sData)
{
try
{
// Write data into an internal byte array
ByteArrayOutputStream strmBytes = new ByteArrayOutputStream();
// Write Java data types into the above byte array
DataOutputStream strmDataType = new DataOutputStream(strmBytes);
byte[] record;
strmDataType.writeUTF(sData);
// Clear any buffered data
strmDataType.flush();
// Get stream data into byte array and write record
record = strmBytes.toByteArray();
rs.addRecord(record, 0, record.length);
// Toss any data in the internal array so writes
// starts at beginning (of the internal array)
strmBytes.reset();
strmBytes.close();
strmDataType.close();
}
catch (Exception e)
{
}
}
appending that returned string to browse list..public String readStream()
{ String rdevice="";
try
{
// Allocate space to hold each record
byte[] recData = new byte[50];
// Read from the specified byte array
ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData);
// Read Java data types from the above byte array
DataInputStream strmDataType = new DataInputStream(strmBytes);
for (int i = 1; i <= rs.getNumRecords(); i++)
{
// Get data into the byte array
rs.getRecord(i, recData, 0);
// Reset so read starts at beginning of array
rdevice=strmDataType.readUTF();
strmBytes.reset();
}
strmBytes.close();
strmDataType.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return rdevice;
}
when I select save the app hanging up and does not switch to alarm that supposed to switch to.
what is the problem ??? can any one help me plz ?![]()
Hi ,
The writing of data looks fine . But retriving from the RMS you are using the for loop assuming that the record name will starts with 1 . It will be better if you use the RecordStoreEnumeration to loop through the record store.
U can USe this
for (int i = 1; i <= rs.getNumRecords(); i++)
{
recData[i]=rs.getRecord(i+1);
}
Anshu Chauhan
J2me Developer
Hi All...
I'm already store the data but the problem is when I close the application the stored data deleted ...
I don't know where is the problem(
the record store is permanent storage, isn't it???
please I need help
thanks in advance
Hi,
Are calling some where RecordStroe method's called as deleteRecordStore()..like in code
Thanks,
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,
honest and Raj really thanks for quick reply
I'm using netbeans mobility package emulator, it does not support bluetooth so i can't know if exception thrown or not,
No I don't call deleteRecordStore() any where of the code
I just close the record store after reading stored data by calling rs.closeRecordStore()
so.. what? 8(
There might be some exception. You sould be certain that there is not any exception. Are you using wireless toolkit or something else?
_______________________________________
admin of discussion board "junk file removers"
IF u tested ur application is on netbean then u wil get this problem i m sure becoz netbeans create temporary Rms .Text it on Create ur project on sun WTk and then test it
Anshu Chauhan
J2me Developer
Hi,
Can you find the path of the RMS file...
Then just open this and check that the data you have just saved is present there or not..
Is this also happening on device too..just check..it should not be happen..
Thanks,
Thanks with Regards,
R a j - The K e r n e l
Join Delhi-NCR Nokia Developer's Community,