MS Access Update Error In Index Positon 0

I am attempting to update a MS Access table and it works fine except for index postion 0.When index 0 is updated it updates index postion 1 instead.For all other positions it works fine.

Plese find code sample hereunder:

stmtUpdateRecord = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

rsUpdateRecord = stmtUpdateRecord.executeQuery("SELECT * FROM Student");

//entity data object set to current primary key

student = getStudent(m_intPk);

boolean found =false;

while (rsUpdateRecord.next() && !found)

{

int intPk = rsUpdateRecord.getInt("StuPrimKey");

//current pk

if (m_intPk == 0)

{

//new resultset pk == current pk

if(intPk == m_intPk)

{

found =true;

result = 1;

}

}

//new resultset pk == resultset pk ordered by firstname. -1 required else updates out of synch

elseif(intPk == m_intPk -1)

{

found =true;

result = 1;

}

}

rsUpdateRecord.updateString("StudentKnum",student.getStuKnum());

rsUpdateRecord.updateString("FirstName",student.getFname());

rsUpdateRecord.updateString("LastName",student.getLname());

rsUpdateRecord.updateString("DOB",student.getDob());

rsUpdateRecord.updateString("MobileNum",student.getTel());

rsUpdateRecord.updateString("CollegeEmail",student.getCmail());

rsUpdateRecord.updateRow();

connection.commit();

[2360 byte] By [sweenya] at [2007-10-3 5:41:45]
# 1

I'm not very fond of this code. Why do you have to select all the students to update one? you iterate through all the student records to find the one with the given primary key and then update it? this is nuts. it's inefficient for two reasons: (1) you have to bring all the student records over the wire with the query, and (2) you potentially have to iterate over all the students in order to update one. If you're lucky, you update the first one. If not, you update the last one. You have no ORDER BY clause to help you, either.

Why don't you just UPDATE STUDENT WHERE ID = ? and bind the primary key you want to update?

you don't need an updatable result set to update an existing student.

%

duffymoa at 2007-7-14 23:49:39 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...