My code attempting to insert NULL into setDouble method in PreparedStatement
ps.setDouble(++i, balance.getAmount());
getAmount() is Double field.
i am able to handle like
if (balance.getAmount() == null ) {
ps.setNull(++i, java.sql.Types.NULL);
}else{
ps.setDouble(++i, balance.getAmount());
}
But my code looks ugly, because my code have many number of setInt setLong setDouble methods.
Is there any way to hanlde smartly or is there any other approach. Please advise me.
You could try
preparedStatement.setObject(i, balance.getAmount(), java.sql.Types.DOUBLE);
setObject(int parameterIndex, Object x, int targetSqlType)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With