java - MySQL Return Predefined Column Value as Int -


i've got mysql query predefines column in query meant integer type:

select id, 1 item_id table other_id = 1; 

when retrieve statement in java classcastexception:

java.lang.float cannot cast java.lang.integer 

i've tried casting value integer using unsigned type:

select id, cast(1 unsigned) item_id table other_id = 1; 

but gives me same type of error:

java.math.biginteger cannot cast java.lang.integer 

i'm not sure if need fix in java or in actual sql statement, i'd value integer.

the place in java can imagine in causing problem bringing value in object because i'm storing record hashmap , don't know exact column type. unfortunately can't change this.

resultsetmetadata metadata = resultset.getmetadata(); int columncount = metadata.getcolumncount(); while(resultset.next()) {     hashmap<string, object> row = new hashmap<string, object>();     for(int i=1; i<=columncount; i++) {         row.put(metadata.getcolumnname(i), resultset.getobject(i));     }     list.add(row); } 

well, if "think" column must contain integers only, should update column within table.

if want quick fix of problem, cast received result within java.

int = (int) rs.getobject("item_id"); 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -