After getting SqlRowSet object from H2-database, before retrieving data from the rows with SqlRowSet.getDouble();
I call SqlRowSet.next();
I've tried doing while(SqlRowSet.next()){}
but this shouldn't be needed as I always only have 1 row in the data .
public SqlRowSet findBySkuSize(String sku, String size) {
return jdbcTemplate.queryForRowSet("SELECT * from PRODUCT_DIMENSIONS where SKU = '" + sku + "' and SIZE = '" + size + "'");
}
the above method populates the SqlRowSet object (in the debugger i can see that there is 1 row shown in the image below.
if(CountRows(dimensionResults) < 1)
{
}
else
{
dimensionResults.next();
someObject.objectSetterMethod(dimensionResults.getDouble("DEPTH"));
}
The above code is what throws an InvalidCursorException The stack trace is too long to paste I guess but this is the error message
Caused by: java.sql.SQLException: Invalid cursor position
at com.sun.rowset.CachedRowSetImpl.next(CachedRowSetImpl.java:1460)
at org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet.next(ResultSetWrappingSqlRowSet.java:697)
... 67 more
org.springframework.jdbc.InvalidResultSetAccessException: Invalid cursor position; nested exception is java.sql.SQLException: Invalid cursor position
at org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet.next(ResultSetWrappingSqlRowSet.java:700)
at com.footlocker.commerce.shipping.service.FreightCalculationService.UpdateProductDimensions(FreightCalculationService.java:72)
at com.footlocker.commerce.shipping.service.FreightCalculationService.UpdateProductList(FreightCalculationService.java:50)
at com.footlocker.commerce.shipping.service.FreightCalculationService.ProcessFreightCalculationRequest(FreightCalculationService.java:41)
at com.footlocker.commerce.shipping.controller.FreightController.Test(FreightController.java:34)
For some reason it's telling me my cursorPosition is at 2? should it start at 0? and how can it be 2 if I only have 1 Row.
Edit: I was able to change the cursor position in the debuger menu from 2 to 0 and dimensionResults.next(); worked.. So why is it that when I instantiate the object it starts at cursor position 2? Im royally confused as to why Java has to be so complicated compared to C# and finding resources to make sense of everything is difficult as well lol.