This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
How to assign big SQL statements in a String variable.. The excerpts given below..
String rsString= "SELECT SO_NUM,ORDERING_CODE,FIN_QTY FROM CCTPL_RAWMATS_ISSUE_DETAIL WHERE ORDERING_CODE= ( SELECT ORDERING_CODE_REAL FROM CCTPL_SALES_QUOT_DETAILS WHERE ORDERING_CODE='099-0004' AND QUOT_NO= (SELECT QUOT_NO FROM CCTPL_SALES_PO_MASTER WHERE PO_NO='004' ) ) AND PO_NO LIKE '004'";
In Compilation above code gives multiple "Unclosed character literal" error..
I would recommend laying the query out in the Java source as you would if it was specified in a SQL script or stored procedure. I've adapted it to my style below (well, not quite). I find it helpful to distinguish between keywords and tables/columns using upper/lower case. The neat little column of plusses is rather sad, but a personal preference. Obviously your project coding standards (or personal taste?!) may preclude you from adopting this style.
Additionally, I think I'm right in saying that, as the sub-queries are both singletons, you could rewrite the query like this:
That should return exactly the same results. I think that makes the query more readable. It should also improve its performance (logical IOs), though I doubt that is an issue.
I know this wasn't what you asked for, but I hope you find it useful in some way.