vino
vino

Reputation: 119

Need to pass range of values to prepared statement

I need to pass range of values to prepared statement.

For eg.

505 is total count

need to divide it by 100

so the ranges will be like 1 to 100 ,101 to 200...501 to 505.

I have a code to implement this. But that is complex way of doing this. Here I've attached the code. Is there any other easy way to do this?

upperValue = maxRowSize;
quotient = rowCount / maxRowSize;
rem = rowCount % maxRowSize;
if (rem == 0) {
    loopcount = quotient;
    finalValue = 0;
} else {
    loopcount = quotient + 1;
    finalValue = rem;
}
lowerValue = 1;

for (int i = 0; i < loopcount; i++) {
    if (finalValue != 0 && i == loopcount - 1) {
        upperValue = (lowerValue - 1) + finalValue;
    }
    resultSet = executeQuery(connection, query, lowerValue, upperValue);

Upvotes: 1

Views: 132

Answers (1)

Srinivas
Srinivas

Reputation: 1790

I think using LIMIT and OFFSET in your (mysql) query would be a better choice.

Check this link for more details.

Upvotes: 1

Related Questions