You should write and
test your SQL in your database's SQL interpreter before putting it into your
Java code. This is the quickest and most reliable way to ensure that your SQL is valid, that it runs against the tables/columns in your database schema, and that it returns the correct results. Until you have done this, your SQL is just a
string that might or might not be correct. Once you know your SQL is correct, you can put it into your Java code. Don't be afraid of the database: if you are writing SQL you should know how to execute it in your database. If you are afraid of executing SQL in your database, you shouldn't be writing SQL in the first place.