while(rs.next()){
Object o = rs.getObject(i);
System.out.println(o.getClass()); //prints java.lang.Integer
}
The problem is that I have a smallint type in the database and the driver returns an Integer type. I am doing some logic at runtime and then trying to insert the value back in the database using the type I was previously handed by the DB.
I would like DB2 to return me a java.lang.Short, but I am not sure if thats possible.
Has anyone encountered this before and what did you do for a workaround?
The basic issue is – I have both int and smallint columns in the DB2 database and I need my java code to figure out which is which based on the result set.
Thanks.
Instead of relying on the type of the Java object returned, ask the resultset for the actual database type of the column:
or
See http://download.oracle.com/javase/6/docs/api/java/sql/ResultSetMetaData.html. The javadoc is such a valuable source of information!