java and mysql issue
Posted on 2011-05-08
I need help in java and mysql here.
MySQL has a inbuilt function
If expr1 is not NULL, IFNULL() returns expr1; otherwise it returns expr2. IFNULL() returns a numeric or string value, depending on the context in which it is used.
I want to use IFNULL function in where clause of my query.
I have a java code like this ..
query = "select * from tableA"; // get all records
query = "select * from tableA where name=' "+name+" ' "; // get records which matches the name.
// several of this kind of blocks
Can I reduce the code with the help of MySQL in-built IFNULL function. My primary objective is to reduce the cyclometric complexity contribution generated out of this approach.
However, when I try to code ,my hunch is ,I dont understand where to put column name in IFNULL ? IFNULL accepts expression but not column name. ...right ? How do I validate the value of a column with the help of this function then ?