i have developed an app that uses Record Store. when i click on the app icon list appears containing 2 options("Save password","Retrieve password").when i click on the password option textfield appears where i have to enter password. After entering password, password is saved in the recordstore.
when i click on the 2 option in the list "Retrieve Password" , password is retreived.
Next time when i run this app, and when i click on the 2 option in the list "Retrieve Password" , it shows
record not exists.
code for save password:
TextField tf=new TextField("Your PASSWORD : ", null, 20, TextField.PASSWORD);
RecordStore rc = RecordStore.openRecordStore("Password", true);
byte[] b=tf.getString().getBytes();
rc.addRecord(b,0,b.length);
rc.closeRecordStore();
code for retreiving password :
TextField tf=new TextField("Your PASSWORD : ", null, 20, TextField.PASSWORD);
RecordStore rc = RecordStore.openRecordStore("Password", true);
byte[] b=new byte[100];
String data=null;
ByteArrayInputStream bis=new ByteArrayInputStream(b);
DataInputStream dis=new DataInputStream(bis);
for(int i=1;i<=rc.getNumRecords();i++)
{
rc.getRecord(i, b, 0);
try {
data = dis.readUTF();
} catch (IOException ex) {
ex.printStackTrace();
}
if (tf.getString().equals(data))
{
System.out.println("Password Exists");
break;
}
if(!(tf.getString().equals(data)))
{
showAlert("Error......", "Password Does not exists");
break;
}
bis.reset();
}
try {
bis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
try {
dis.close();
} catch (IOException ex) {
ex.printStackTrace();
}
rc.closeRecordStore();
}
catch(RecordStoreException ex)
{
showAlert("Error..", ex.toString());
}

Reply With Quote


