Java Reference
In-Depth Information
languages represent SQL as a string type, which introduces concatenation for long
SQL statements. Consider the following simple SQL statement:
SELECT
PRODUCTID,
NAME,
DESCRIPTION,
CATEGORY
FROM PRODUCT
WHERE CATEGORY = ?
When embedded in a String data type in a modern programming language such
as Java, this gentle SQL statement becomes a mess of multiple language character-
istics and unmanageable code:
String s = "SELECT"
+ " PRODUCTID,"
+ " NAME,"
+ " DESCRIPTION,"
+ " CATEGORY"
+ " FROM PRODUCT"
+ " WHERE CATEGORY = ?";
Simply forgetting to lead the FROM clause with a space will cause a SQL error to
occur. You can easily imagine the trouble a complex SQL statement could cause.
Therein lies one of the key advantages of i BATIS : the ability to write SQL the
way it was meant to be written. The following gives you a sense of what an i BATIS
mapped SQL statement looks like:
SELECT
PRODUCTID,
NAME,
DESCRIPTION,
CATEGORY
FROM PRODUCT
WHERE CATEGORY = #categoryId#
Notice how the SQL does not change in terms of structure or simplicity. The biggest
difference in the SQL is the format of the parameter #categoryId# , which is nor-
mally a language-specific detail. i BATIS makes it portable and more readable.
Now that we have our SQL out of the source code and into a place where we
can work with it more naturally, we need to link it back to the software so that it
can be executed in a way that is useful.
Search WWH ::




Custom Search