An “invalid cursor state” error appears when I run this code.
I use this code to obtain the result set from an Access database, and then store it in a table.
This segment of code is only to obtain the data from the result set:
data=new Object[numberOfRows][numberOfColumns];
for(int i=0;i<numberOfRows;i++){
int j=0;
while(j<numberOfColumns){
// int colType=rsmd.getColumnType(j+1);
// System.out.println(colType);
data[i][j]=rs.getInt("course_id");
System.out.print("0th: "+data[i][j]+" ");
j++;
data[i][j]=rs.getString("course_name");
System.out.print("1st:"+data[i][j]+" ");
j++;
data[i][j]=rs.getString("course_date");
System.out.print("2nd:"+data[i][j]+" ");
j++;
data[i][j]=rs.getString("course_number");
System.out.print("3rd: "+data[i][j]+" ");
j++;
System.out.print("j:"+j);
}
System.out.print("Done line:"+i);
}
I think that the main problem is that you never call
rs.next()to scroll the cursor. However, based on your clarification of the record structure, yourwhileloop seems messed up too. Try the following: