10 Best ways to write optimized SQL in Java
1. Forgetting about NULL Misunderstanding NULL is probably the biggest mistake a Java developer can make when writing SQL. This is also (but not exclusively) due to the fact that NULL is also called UNKNOWN. If it were only called UNKNOWN, it would be easier to understand. Another reason is that JDBC maps SQL NULL to Java null when fetching data or when binding variables. This may lead to thinking that NULL = NULL (SQL) would behave the same way as null == null (Java) One of the crazier examples of misunderstanding NULL is when NULL predicates are used with row value expressions . Another, subtle problem appears when misunderstanding the meaning of NULL in NOT IN anti-joins . The Cure: Train yourself. There’s nothing but explicitly thinking about NULL, every time you write SQL: Is this predicate correct with respect to NULL? Does NULL affect the result of this function? 2. Processing data in Java memory Few Java developers know SQL very well. The occasion...