SQLBuilder

public class SQLBuilder

SQLBuilder is a tool which can construct prepared SQL statements from the specified table, keys, and columns.

Author:Hugo Y. K. Lam

Constructors

SQLBuilder

public SQLBuilder(String table, String key, String[] columns)

Creates a new instance of SQLBuilder.

Parameters:
  • table – the table name.
  • key – the comma delimited set of keys of the table.
  • columns – the columns of the table.

SQLBuilder

public SQLBuilder(String table, String[] keys, String[] columns)

Creates a new instance of SQLBuilder.

Parameters:
  • table – the table name.
  • keys – the keys of the table.
  • columns – the columns of the table.

Methods

getColumns

public String[] getColumns()

Gets the columns.

Returns:the columns.

getDeleteStatement

public String getDeleteStatement()

Gets the DELETE statement.

Returns:the DELETE statement.

getInsertStatement

public String getInsertStatement()

Gets the INSERT statement.

Returns:the INSERT statement.

getInsertStatement

public String getInsertStatement(String[] cols)

Gets the INSERT statement.

Parameters:
  • cols – the columns to be updated.
Returns:

the INSERT statement.

getKeys

public String[] getKeys()

Gets the keys.

Returns:the keys.

getSelectStatement

public String getSelectStatement()

Gets the SELECT statement.

Returns:the SELECT statement.

getTable

public String getTable()

Gets the table name.

Returns:the table name.

getUpdateStatement

public String getUpdateStatement()

Gets the UPDATE statement.

Returns:the UPDATE statement.

getUpdateStatement

public String getUpdateStatement(String[] cols)

Gets the UPDATE statement.

Parameters:
  • cols – the columns to be updated.
Returns:

the UPDATE statement.

isValid

public boolean isValid()

Checks if this SQL builder is valid. It is valid if and only if the table, columns, and keys have been defined.

Returns:true if this SQL builder is valid.