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)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git