Class SQLBuilder
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.builders.SQLBuilder
-
- Direct Known Subclasses:
DeleteBuilder
,IndexBuilder
,InsertBuilder
,QueryBuilder
,TableBuilder
,UpdateBuilder
public abstract class SQLBuilder extends java.lang.Object
An abstract builder class for creating sql statements.- Since:
- 1.4.0
-
-
Constructor Summary
Constructors Constructor Description SQLBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract TypedStatement
build(Database db)
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.java.sql.PreparedStatement
buildPreparedStatement(Database db)
Creates aPreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.protected java.lang.StringBuilder
getSql()
java.sql.PreparedStatement
getStatement()
Returns thePreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.protected SQLBuilder
setStatement(java.sql.PreparedStatement statement)
java.lang.String
toString()
Returns the sql statement as a string.
-
-
-
Method Detail
-
buildPreparedStatement
public final java.sql.PreparedStatement buildPreparedStatement(Database db) throws java.sql.SQLException
Creates aPreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.- Parameters:
db
- the database to request thePreparedStatement
object from- Returns:
- a new
PreparedStatement
object containing the pre-compiled SQL statement - Throws:
java.sql.SQLException
- if a database access error occurs
-
build
public abstract TypedStatement build(Database db) throws java.sql.SQLException
Runs buildPreparedStatement and passes this object to a new instance ofTypedStatement
.- Parameters:
db
- the database to request thePreparedStatement
object from- Returns:
- a new instance of
TypedStatement
- Throws:
java.sql.SQLException
- if a database access error occurs
-
getStatement
@Contract(pure=true) public final java.sql.PreparedStatement getStatement()
Returns thePreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.- Returns:
- the
PreparedStatement
object, null if buildPreparedStatement has not been run
-
setStatement
protected SQLBuilder setStatement(java.sql.PreparedStatement statement)
-
getSql
protected java.lang.StringBuilder getSql()
-
toString
public java.lang.String toString()
Returns the sql statement as a string.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the sql statement as a string
-
-