MrTerrence
asked on
Add a record in recordset doesnt append at the end of record, but replace deleted record.
Hi all,
Let's say i have three records in a record set: Record 1,2,3. When i deleted record 2, now there is: Record 1,3. When i add a new record again, it shows that the new record is added as record 4,
I suppose the sequence will be 1,3,4. But when i recreate a new recordset, create a recordenumeration and try to read from the beginning..what i read out is record 1,4,3. :O!? Looks like the record 4 is not appended at the end of the recordset but replaced the deleted record?
I guess somehow the recordset pointer is still pointing at the location od the deleted record?
my code is quite standard, i always open a recordstore and close it after use. like this:
when deleting record 2 (simplified..)
========================
recordStore = RecordStore.openRecordStor e(recordSt oreName,tr ue)
recordStore.deleteRecord(2 );
recordStore.closeRecordSto re();
when inserting new record
===================
recordStore = RecordStore.openRecordStor e(recordSt oreName,tr ue)
byte[] b = .........;
int ID = recordStore.addRecord(b, 0, b.length); // this ID shows the record added is record 4 recordStore.closeRecordSto re();
When enumerating again
=================
db2 =RecordStore.openRecordSto re(picRsNa me,true);
RecordEnumeration recordEnumeration = db2.enumerateRecords(null, null,false );
while(recordEnumeration.ha sNextEleme nt()){
int id = recordEnumeration.nextReco rdId();
System.out.println("readin g >> record ID:" + id); //******************Over here, the output is 1, 4,3!
ByteArrayInputStream bais = new ByteArrayInputStream(db2.g etRecord(i d));
...............reading bais...
}
db2.closeRecordStore();
===
p/s: To ensure addRecord() really add at the new record AFTER the last record, i even tried to go through a nextRecord() loop and makesure the pointer is pointing at last record before i call addRecord(), but the sequence read out is still wrong.
Let's say i have three records in a record set: Record 1,2,3. When i deleted record 2, now there is: Record 1,3. When i add a new record again, it shows that the new record is added as record 4,
I suppose the sequence will be 1,3,4. But when i recreate a new recordset, create a recordenumeration and try to read from the beginning..what i read out is record 1,4,3. :O!? Looks like the record 4 is not appended at the end of the recordset but replaced the deleted record?
I guess somehow the recordset pointer is still pointing at the location od the deleted record?
my code is quite standard, i always open a recordstore and close it after use. like this:
when deleting record 2 (simplified..)
========================
recordStore = RecordStore.openRecordStor
recordStore.deleteRecord(2
recordStore.closeRecordSto
when inserting new record
===================
recordStore = RecordStore.openRecordStor
byte[] b = .........;
int ID = recordStore.addRecord(b, 0, b.length); // this ID shows the record added is record 4 recordStore.closeRecordSto
When enumerating again
=================
db2 =RecordStore.openRecordSto
RecordEnumeration recordEnumeration = db2.enumerateRecords(null,
while(recordEnumeration.ha
int id = recordEnumeration.nextReco
System.out.println("readin
ByteArrayInputStream bais = new ByteArrayInputStream(db2.g
...............reading bais...
}
db2.closeRecordStore();
===
p/s: To ensure addRecord() really add at the new record AFTER the last record, i even tried to go through a nextRecord() loop and makesure the pointer is pointing at last record before i call addRecord(), but the sequence read out is still wrong.
Is the second sql statement look like this?
SELECT * FROM TABLE ORDER BY ID
'ORDER BY ID' will sort the recordset by 'ID' field ascendently.
SELECT * FROM TABLE ORDER BY ID
'ORDER BY ID' will sort the recordset by 'ID' field ascendently.
ASKER
Hi Gnoon,
I m not sure did u misunderstood anything, hmm but I m working on a J2ME mobile application. The recordset i mention is within the Record Management System (RMS)...so i didnt use any SQL in sorting actually.
Actually i didnt sort at all when i try to read out the records again, as shown in part 3 of the code, i just open the recordset, create an enumeration, then loop through each record. i thought this will give me the record one by one in the sequence how i added them.
any clues?
I m not sure did u misunderstood anything, hmm but I m working on a J2ME mobile application. The recordset i mention is within the Record Management System (RMS)...so i didnt use any SQL in sorting actually.
Actually i didnt sort at all when i try to read out the records again, as shown in part 3 of the code, i just open the recordset, create an enumeration, then loop through each record. i thought this will give me the record one by one in the sequence how i added them.
any clues?
Sorry man, maybe I cant help you because I' not familiar with J2ME :-/ .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Though i didnt get a confirmative explaination on the scenario above (and i cant find any documentation abt it), but both the methods mentioned are workable. Thank you.
Actually, no matter what data sequence stored in the db, but how to get it in your sequence by programming.