In Java, I have defined k as
double k=0.0;
I am taking data from database and adding the same using while
loop,
while(rst.
I assume rst
is a ResultSet. Make sure you are using getBigDecimal rather than Double.parseDouble(rst.getString(5))
:
BigDecimal k = BigDecimal.ZERO;
while(rst.next()) {
k = k.add(rst.getBigDecimal(5));
}
And first of all: why aren't you adding these numbers in the database directly using appropriate SQL SUM
query?