File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Big SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Big SQL" Watch "Big SQL" New topic
Author

Big SQL

Pranit Saha
Ranch Hand

Joined: Sep 09, 2001
Posts: 130
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..

Pranit..
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
Using a StringBuffer is better, to prevent memory leak.
Dmitry Melnik
Ranch Hand

Joined: Dec 18, 2003
Posts: 328
There will be no memory leak, if all Strings being added are constants. The result will be calculated at compile time.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Pranit,

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.

Jules
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

... but Jules, if you hadn't mentioned it, I would.


http://home.arcor.de/hirnstrom/bewerbung
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Big SQL
 
Similar Threads
Login Servlet
classcastException
How to get number of rows into Single row as comma separated.
prepared statement
how to search?