BigDecimal Error

后端 未结 5 1788
走了就别回头了
走了就别回头了 2021-01-13 01:58

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.         


        
5条回答
  •  暖寄归人
    2021-01-13 02:15

    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?

提交回复
热议问题