jdbc query rewritten