if (myRs.next()) { // <-- Advances to the next row
while (k < i) { // <-- What is this loop supposed to do?
}
myRs.next(); // <-- Advances to the next row, but that
// row is never used. Delete this line.
k++;
}

To retrieve up toi (bad name, use rowsToRead or something like that), use a combined for loop: