nl.knowledgeplaza.util.jdbc
Class SqlBuilder
java.lang.Object
nl.knowledgeplaza.util.jdbc.SqlBuilder
public class SqlBuilder
- extends java.lang.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();
lSqlBuilder.append("select field1");
lSqlBuilder.append(" from table");
lSqlBuilder.append(" where field2 = ?", new Integer(1)); // or just 1 in Java 1.5+ with autocasting
lSqlBuilder.append(" and field2 = ?", new Long(2));
lSqlBuilder.append(" and field3 = ? or field4 = ?", new Object[]{ new Long(3), new Long(4)} );
- Version:
- $Revision: 1.2 $
|
Field Summary |
static java.lang.String |
SOURCECODE_VERSION
Standard variable for determining version of a class file. |
|
Method Summary |
void |
append(java.lang.String part)
|
void |
append(java.lang.String part,
java.lang.Object parameter)
|
void |
append(java.lang.String part,
java.lang.Object[] parameters)
|
void |
appendValuesText()
Append a values text with the same number of ? as there are parameters |
java.sql.PreparedStatement |
createPreparedStatement(java.sql.Connection connection)
Create prepared statement with the parameters already filled (setXXX calls). |
java.lang.Object[] |
getParameterArray()
|
java.util.List |
getParameters()
|
java.lang.String |
getSql()
|
java.sql.PreparedStatement |
prepareStatement(java.sql.Connection connection)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SOURCECODE_VERSION
public static final java.lang.String SOURCECODE_VERSION
- Standard variable for determining version of a class file.
- See Also:
- Constant Field Values
SqlBuilder
public SqlBuilder()
append
public void append(java.lang.String part)
append
public void append(java.lang.String part,
java.lang.Object parameter)
append
public void append(java.lang.String part,
java.lang.Object[] parameters)
appendValuesText
public void appendValuesText()
- Append a values text with the same number of ? as there are parameters
getSql
public java.lang.String getSql()
- Returns:
getParameters
public java.util.List getParameters()
- Returns:
getParameterArray
public java.lang.Object[] getParameterArray()
- Returns:
createPreparedStatement
public java.sql.PreparedStatement createPreparedStatement(java.sql.Connection connection)
throws java.sql.SQLException
- Create prepared statement with the parameters already filled (setXXX calls).
- Parameters:
connection -
- Returns:
-
- Throws:
java.sql.SQLException
prepareStatement
public java.sql.PreparedStatement prepareStatement(java.sql.Connection connection)
throws java.sql.SQLException
- Throws:
java.sql.SQLException
Copyright © 2010. All Rights Reserved.