I have the following SQL Query :
SELECT COUNT(*) FROM DOG where ID = 'SampleId';
I am trying to write this in java
:
public int returnCountOfDogTable(String id){
String sql= "SELECT COUNT(*) FROM DOG WHERE ID =:id";
Query query = persistence.entityManager().createNativeQuery(sql);
query.setParameter("id", id);
List<Integer> resultList = query.getResultList();
int result = resultList.get(0);
return result;
}
However I get this exception:
java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Integer
How can I solve this?