2017-04-05 59 views
1

我DAO與保存方法的PreparedStatement setBigDecimal從PARAMS

public void save(BigDecimal cashBackAmount){ 
try (Connection connection = dataSource.getConnection(); 
      PreparedStatement stmt = connection.prepareStatement(query)) { 
      stmt.setBigDecimal(1, cashBackAmount); 
      stmt.executeUpdate(); 
     } catch (SQLException e) { 
      log.error(e.getMessage()); 
      throw e; 
     } 
    } 
} 

和findbug說:

FindBugs: Unchecked/unconfirmed cast This cast is unchecked, and not all instances of the type casted from can be cast to the type it is being cast to. Check that your program logic ensures that this cast will not fa 

我怎麼能setBigDecimal?

stmt.setBigDecimal(1, new BigDecimal(????)); 
+2

您確定警告是針對該行嗎?沒有任何事情會發生。你得到一個BigDecimal參數並將它提供給一個採用BigDecimal參數的方法。 –

回答

2

只要忽略警告/錯誤。這種情況下的信息是完全沒有意義的。

很明顯,您已經收到BigDecimal。所以你不可能收到其他的東西。

+0

爲什麼然後錯誤消失。謝謝 – user5620472