When the error message says that you have a syntax error in your SQL, then what
you should do is to look at your SQL and see what's wrong with it. That should be fairly obvious, no? So why not put in a debugging statement which outputs the SQL to the console so you can see it (and not just some Java code which builds it)?