Sqlbuilder is a SQL build library that reduces the burden of generating SQL queries in Java programs. It uses a programming language (Java) to generate code (that is, SQL) for another language. It is characterized by encapsulating SQL syntax in lightweight, Easy-to-use Java objects, following a builder paradigm similar to StringBuilder. It can change many common SQL syntax and run-time errors to Java compile-time errors.
A simple SQL select query code embedded in a Java program, as follows:
Assuming a produced of predefined string constants
String selectquery = "Select" + T1_col1 + "," + T1_col2 + "," +
&http://www.aliyun.com/zixun/aggregation/37954.html ">NBSP; T2_col1 + "from" + TABLE1 + "" + T1 + "INNER JOIN" +
TABLE2 + "" + T2 + "on (" + t1_idcol + "=" + T2_idcol +
") Order BY" + t1_col1;
The code to try to improve is as follows:
String selectquery = Messageformat.format (
' Select {0},{1},{2} from {3} {4} ' INNER JOIN {5} {6} ' ({7} = {8}) +
' ORDER by {9} ',
T1_col1, T2_col2, T2_col1, TABLE1, T1, TABLE2, T2,
T1_idcol, T2_idcol, t1_col1);
The Sqlbuilder class corresponds to the following code:
Assuming these objects have already been created
Table table1, table2;
Column t1col1, T1col2, t2col1;
Join JOINOFT1ANDT2;
String SelectQuery =
(New SelectQuery ())
. Addcolumns (T1col1, T1col2, T2col1)
. Addjoin (SelectQuery.JoinType.INNER_JOIN, JOINOFT1ANDT2)
. Addorderings (T1col1)
. Validate (). toString ();
The Sqlbuilder (OPENHMS) version 2.0.10 is primarily about adding flexibility to support SQL constructs. The associated SQL construct has no alias handling table, and dbtable can now build a clear alias. Add SelectQuery addcustomjoin to allow full 17813.html "> customizable join clauses. Combocondition, Unarycondition, binarycondition, and comboexpression can now customize operators. Now all the options for the condition and expression to disable the wrapping bracket.
Software Information: http://openhms.sourceforge.net/sqlbuilder/
Download Address: Http://nchc.dl.sourceforge.net/project/openhms/sqlbuilder/sqlbuilder%202.0.10/sqlbuilder-2.0.10.jar