2017-04-05 58 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