nl.knowledgeplaza.util.jdbc
Class SqlBuilder
java.lang.Object
nl.knowledgeplaza.util.jdbc.SqlBuilder
public class SqlBuilder
- extends Object
A utility class to build SQL in a source code readable form.
It allows spreading the SQL over multiple lines and concats using a StringBuffer,
and at the same time allows placing the parameter values next to the place where they are used (instead of all the way at the end).
For example:
SqlBuilder lSqlBuilder = new SqlBuilder()
.append("select field1")
.append(" from table")
.append(" where field2 = ?", new Integer(1)) // or just 1 in Java 1.5+ with autocasting
.append(" and field2 = ?", new Long(2))
.append(" and field3 = ? or field4 = ?", new Object[]{ new Long(3), new Long(4)} )
;
- Version:
- $Revision: 1.3 $
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SOURCECODE_VERSION
public static final String SOURCECODE_VERSION
- Standard variable for determining version of a class file.
- See Also:
- Constant Field Values
SqlBuilder
public SqlBuilder()
append
public SqlBuilder append(String part)
append
public SqlBuilder append(String part,
Object parameter)
append
public SqlBuilder append(String part,
Object[] parameters)
appendValuesText
public SqlBuilder appendValuesText()
- Append a values text with the same number of ? as there are parameters
getSql
public String getSql()
- Returns:
getParameters
public List getParameters()
- Returns:
getParameterArray
public Object[] getParameterArray()
- Returns:
createPreparedStatement
public PreparedStatement createPreparedStatement(Connection connection)
throws SQLException
- Create prepared statement with the parameters already filled (setXXX calls).
- Parameters:
connection -
- Returns:
-
- Throws:
SQLException
prepareStatement
public PreparedStatement prepareStatement(Connection connection)
throws SQLException
- Throws:
SQLException
Copyright © 2012 KnowledgePlaza. All Rights Reserved.