Apache DBUtils: Standard way to handle different datatype returned from SQL (INT/NULL)?

167 views Asked by At

Is there a standard proper java code to properly handle the following datatype which the result may possible returned as integer or null? I'm using common-dbutils to perform query execution.

--MSSQL
QUERY ="select ID from Users where Name='test'" --ID= int type
QueryRunner run = new QueryRunner();
int results = run.query(connection,QUERY, new ScalarHandler<Integer>()); 

ID returned as INT if where condition met.

ID returned as NULL if where condition not met. (Throw exception since unable to cast into INT)

Any standard java datatype/way should I returned to handle these kind of different scenarios?

0

There are 0 answers