I've been moving an existing project from jdbc to jdbi, and I've been making much use out of jdbi's beautiful SQL Object API. We're using mysql.
While the SQL Object API can construct handled queries that are known at compile time, I couldn't find a way of generating queries at run time.
Specifically, I want to be able to do something like this:
@SqlUpdate(
"UPDATE record SET "+
@IfNotZero("foo") "foo=:foo" +
@IfNotNull("bar") "bar=:bar" +
@IfNotNull("baz") "baz=:baz" +
"WHERE id=:id"
)
public abstract int updateRecord(
@Bind("id") int id,
@Bind("foo") int foo,
@Bind("bar") String bar,
@Bind("baz") String baz
);