SQL生成类库 SqlBuilder
jopen
13年前
<div dir="ltr" id="result_box"> SqlBuilder 是一个Java的类库,它试图帮你避免在Java程序内直接书写SQL查询的痛苦。你只需要使用 SqlBuilder 的方法,它就可以帮你生成对应的 SQL 数据库查询语句,例如下面一个SQL语句: </div> <div dir="ltr"> <pre>String selectQuery = "SELECT " + T1_COL1 + "," + T1_COL2 + "," + T2_COL1 + " FROM " + TABLE1 + " " + T1 + " INNER JOIN " + TABLE2 + " " + T2 + " ON (" + T1_IDCOL + " = " + T2_IDCOL + ") ORDER BY " + T1_COL1;</pre> </div> <p>对应的 SqlBuilder 的代码是:</p> <pre>// 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();</pre> <p>更多的示例代码请看<a href="/misc/goto?guid=4959518024145743663" target="_blank">这里</a>。<br /> </p> <p><strong>项目主页:</strong><a href="http://www.open-open.com/lib/view/home/1328448291937" target="_blank">http://www.open-open.com/lib/view/home/1328448291937</a></p>