I am having table stored in database i am trying to retrieve all data in it
Why i get this error when i tried to retrieve all records in my database?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 185
at warsh01.selectStmt01.getObjectIDsFromDB(selectStmt01.java:83)
public static int[] getObjectIDsFromDB (String Dbnum) throws SQLException{
String selectSQL = "SELECT ID FROM " + Dbnum +.tabName ";
dbConnection = getDBConnection();
preparedStatement = dbConnection.prepareStatement(selectSQL);
ResultSet rs = preparedStatement.executeQuery();
rs.last();
int[] rsIds=new int[rs.getRow()];
rs.beforeFirst();
int counter = 1;
while (rs.next()) {
rsIds[counter]=rs.getInt(1);
counter++; // the error is pointing in this line
}
return rsIds;
}
in the main method when i tried to run it i got the above exception
int [] IdsArray ;
pathIdsArray = getObjectIDsFromDB ("za");
List<ObjClass> objItm=new ArrayList<>();
for (int i = 1; i < IdsArray.length; i++) {
Item1 = new ObjClass ();
objectItem1.color=Color.blue;
objectItem1.LoadFromDB("za", IdsArray[i]);
objItm.add(Item1);
}