DEV Community

Cover image for MySQL query default value is query is NULL
Goffity Corleone
Goffity Corleone

Posted on

MySQL query default value is query is NULL

Problem when wanting to mapping values from MySQL query to Object in JAVA but MySQL Query returns NULL
If Application is written in spring boot with JDBCTemplate and mapping to Object, the exception will occur.

org.springframework.beans.TypeMismatchException
Enter fullscreen mode Exit fullscreen mode

can be solved by use IFNULL

SELECT IFNULL(emp_id,0) FROM emp WHERE 1=0;
Enter fullscreen mode Exit fullscreen mode

Output

0
Enter fullscreen mode Exit fullscreen mode

Reference:
https://dev.mysql.com/doc/refman/5.7/en/flow-control-functions.html
https://www.w3schools.com/sql/func_mysql_ifnull.asp

Top comments (0)