Package tools.sql
Class SqlBuilder
java.lang.Object
tools.jdbc.JdbcBuilder
tools.sql.SqlBuilder
- All Implemented Interfaces:
Serializable
Deprecated.
PrepareStatement builder support
How to use a SELECT
SqlBuilder sql = new SqlBuilder()
.select("t.id", "t.name")
.from("testTable t")
.where()
.andCondition("t.name", "=", "Test")
.andCondition("t.created", ">=", someDate);
for (ResultSet rs : sql.executeSelect(dbConnection)) {
int id = rs.getInt(1);
String name = rs.getString(2);
}
How to use a INSERT
SqlBuilder sql = new SqlBuilder()
.insert("testTable")
.write("(")
.columnInsert("id", 10)
.columnInsert("name", "Test")
.columnInsert("date", someDate)
.super.write(")");
sql.executeUpdate(dbConnection);
How to use a UPDATE
SqlBuilder sql = new SqlBuilder()
.update("testTable")
.columnUpdate("name", "Test")
.columnUpdate("date", SOME_DATE)
.where()
.andCondition("id", "IN", 10, 20, 30)
.andCondition("created BETWEEN ? AND ?", null, someDate, someDate.plusMonths(1))
.andCondition("name", "IS NOT NULL")
sql.executeUpdate(dbConnection);
For more information see a jUnit test.- Author:
- Pavel Ponec
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class tools.jdbc.JdbcBuilder
JdbcBuilder.MarkerEnvelope, JdbcBuilder.SqlEnvelope -
Field Summary
Fields inherited from class tools.jdbc.JdbcBuilder
arguments, columnCounter, conditionCounter, insertMode, ITEM_SEPARATOR, SPACE, sql, VALUE_MARKER -
Constructor Summary
ConstructorsConstructorDescriptionDeprecated.SqlBuilder(List<CharSequence> sql, List<Object> arguments) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionaddArguments(Object... values) Deprecated.Add argument values with no SAPARATOR and no MARKER (for a common use)protected SqlBuilderDeprecated.Add a value to SQL (inlucing MARKER)andCondition(CharSequence sqlCondition, String operator, Object value) Deprecated.Add a condition for a valid argument joined by AND operatorandCondition(CharSequence sqlCondition, String operator, Object... values) Deprecated.Add a condition for a multivalue argument joined by AND operatorfinal SqlBuildercolumn(CharSequence column) Deprecated.Add new columncolumnInsert(CharSequence column, Object value) Deprecated.Set new value to column by templatename = ?columnUpdate(CharSequence column, Object value) Deprecated.Set new value to column by templatename = ?condition(CharSequence sqlCondition, String operator, Object value) Deprecated.Add a condition for an argument with lengthdelete(@NotNull CharSequence table) Deprecated.Write WHEREfrom(@NotNull CharSequence... tables) Deprecated.Write FORM tablesinsert(@NotNull CharSequence table) Deprecated.Write WHEREorCondition(CharSequence sqlCondition, String operator, Object value) Deprecated.Add a condition for a valid argument joined by OR operatororCondition(CharSequence sqlCondition, String operator, Object... values) Deprecated.Add a condition for a multivalue argument joined by OR operatorselect(@NotNull CharSequence... columns) Deprecated.Write SELECT columnsupdate(@NotNull CharSequence table) Deprecated.Write WHEREDeprecated.Add an argument value (including a SEPARATOR and a MARKER) for buidling a SQL INSERT statementwhere()Deprecated.Write WHEREfinal SqlBuilderwrite(CharSequence sqlFragment) Deprecated.Write a sql fragment including a space beforefinal SqlBuilderwrite(SqlBuilder builder) Deprecated.final SqlBuilderwriteMany(CharSequence... sqlFragments) Deprecated.Write many sql fragments including a space beforefinal SqlBuilderwriteManyNoSpace(CharSequence... sqlFragments) Deprecated.Write many sql fragments with no space beforefinal SqlBuilderwriteNoSpace(CharSequence sqlFragment) Deprecated.Write a sql fragment with no space beforeMethods inherited from class tools.jdbc.JdbcBuilder
createValuePrinter, executeSelect, executeSelect, executeUpdate, getArguments, getBufferSizeEstimation, getSql, getSql, prepareStatement, toString, uniqueValue, uniqueValueOptional, write, writeOperator
-
Constructor Details
-
SqlBuilder
public SqlBuilder()Deprecated. -
SqlBuilder
Deprecated.
-
-
Method Details
-
select
Deprecated.Write SELECT columns -
from
Deprecated.Write FORM tables -
where
Deprecated.Write WHERE -
insert
Deprecated.Write WHERE -
update
Deprecated.Write WHERE -
delete
Deprecated.Write WHERE -
addArguments
Deprecated.Description copied from class:JdbcBuilderAdd argument values with no SAPARATOR and no MARKER (for a common use)- Overrides:
addArgumentsin classJdbcBuilder- See Also:
-
addValue
Deprecated.Description copied from class:JdbcBuilderAdd a value to SQL (inlucing MARKER)- Overrides:
addValuein classJdbcBuilder- Parameters:
value- Anullvalue is ignored- See Also:
-
value
Deprecated.Description copied from class:JdbcBuilderAdd an argument value (including a SEPARATOR and a MARKER) for buidling a SQL INSERT statement- Overrides:
valuein classJdbcBuilder- See Also:
-
condition
Deprecated.Description copied from class:JdbcBuilderAdd a condition for an argument with length- Overrides:
conditionin classJdbcBuilder- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?". Send anullvalue to ignore the method.operator- An optional operator is followed by theJdbcBuilder.VALUE_MARKERautomaticallyvalue- Add a value to arguments including a markup to the SQL statement. To ignore the value, send anull. An array is supported
-
orCondition
Deprecated.Description copied from class:JdbcBuilderAdd a condition for a multivalue argument joined by OR operator- Overrides:
orConditionin classJdbcBuilder- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theJdbcBuilder.VALUE_MARKERautomaticallyvalues- The value of the condition (a replacement for the question character)
-
orCondition
Deprecated.Description copied from class:JdbcBuilderAdd a condition for a valid argument joined by OR operator- Overrides:
orConditionin classJdbcBuilder- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theJdbcBuilder.VALUE_MARKERautomaticallyvalue- Add the value to arguments including a markup to the SQL statement. To ignore the value, send anull.
-
andCondition
Deprecated.Description copied from class:JdbcBuilderAdd a condition for a multivalue argument joined by AND operator- Overrides:
andConditionin classJdbcBuilder- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theJdbcBuilder.VALUE_MARKERautomaticallyvalues- The value of the condition (a replacement for the question character)
-
andCondition
Deprecated.Description copied from class:JdbcBuilderAdd a condition for a valid argument joined by AND operator- Overrides:
andConditionin classJdbcBuilder- Parameters:
sqlCondition- A condition in the SQL format like the next:"table.id = ?"operator- An optional operator is followed by theJdbcBuilder.VALUE_MARKERautomaticallyvalue- Add the value to arguments including a markup to the SQL statement. To ignore the value, send anull.
-
columnInsert
Deprecated.Description copied from class:JdbcBuilderSet new value to column by templatename = ?- Overrides:
columnInsertin classJdbcBuilder
-
columnUpdate
Deprecated.Description copied from class:JdbcBuilderSet new value to column by templatename = ?- Overrides:
columnUpdatein classJdbcBuilder
-
column
Deprecated.Description copied from class:JdbcBuilderAdd new column- Overrides:
columnin classJdbcBuilder
-
writeManyNoSpace
Deprecated.Description copied from class:JdbcBuilderWrite many sql fragments with no space before- Overrides:
writeManyNoSpacein classJdbcBuilder
-
writeMany
Deprecated.Description copied from class:JdbcBuilderWrite many sql fragments including a space before- Overrides:
writeManyin classJdbcBuilder
-
writeNoSpace
Deprecated.Description copied from class:JdbcBuilderWrite a sql fragment with no space before- Overrides:
writeNoSpacein classJdbcBuilder- Parameters:
sqlFragment- An empty or null fragment is ignored.
-
write
Deprecated.Description copied from class:JdbcBuilderWrite a sql fragment including a space before- Overrides:
writein classJdbcBuilder- Parameters:
sqlFragment- An empty ornullvalue is ignored.
-
write
Deprecated.
-
SqlParamBuilderclass rather from the release 2.26.