I am using Netbeans 6.9.1, and glassfish 3.1, the DB is MySql.
There is a table in the database called HotelNames, i need to write a SQL and pass the Hotel name to get its hotel ID. I get an exception which i am unable to solve.
@Override
public int GetHotelID(String hotellName) {
Query query = em.createNativeQuery("select ID from HotelNames where hotName ='"+ hotellName+"'");
String hotelID = (String) query.getSingleResult();
return Integer.parseInt(hotelID );
}
The exception i get points to the SQL i wrote in the above code
Caused by: java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.String
MySQL create table looks like;
CREATE TABLE HotelNames (`ID` BIGINT NOT NULL AUTO_INCREMENT, `hotName` VARCHAR(255), PRIMARY KEY (`ID`));
I think its because of the BIGINT in the SQL and int in the code that's causing this, but i am unable to solve this.