I am trying to run a simple SQL(native) query within a hibernate application.
SELECT COUNT(*) from users
The answer to the select may be saved into a integer. How can i do this without having to create a model class in Hibernate?
I am trying to run a simple SQL(native) query within a hibernate application.
SELECT COUNT(*) from users
The answer to the select may be saved into a integer. How can i do this without having to create a model class in Hibernate?
int count=0;    
Resultset rs=Statement.ExecuteQuery("SELECT COUNT(*) as count from users");
    if(rs.next()){
     count=rs.getInt("count");
    }
System.out.println(count);
Hibernate 5.0.9.Final will give that result as a BigInteger type object. Assuming you have an EntityManager, then use:
BigInteger r = (BigInteger) em.createNativeQuery("select count(*) from user").getSingleResult();
System.out.println(r);
This is a simple question and you should be able to find the answer easily on stackoverflow:
Resultset rs=Statement.ExecuteQuery("SELECT COUNT(*) as number from users");
while(rs.next()){
 Long count =rs.getLong("number");
    }