I\'m using a Double variable which holds the Item price. That variable is stored in postgresql database under a column of money type. I use setBigDecimal(position,value) SQL fu
This program illustrates conversion in both directions between Double and BigDecimal:
import java.math.BigDecimal;
public class Test {
public static void main(String[] args) {
Double d1 = 1.3;
BigDecimal bd1 = BigDecimal.valueOf(d1.doubleValue());
Double d2 = bd1.doubleValue();
System.out.println(d2);
}
}
Note that the conversion to Double may not be exact.
Obviously priceSpinner.getValue()
returns BigDecimal
and you're trying to convert it to double
and then back to BigDecimal
.
Why don't you just do?
insertStmt.setBigDecimal(position, (BigDecimal) priceSpinner.getValue());