Class TypedStatement
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.TypedStatement
-
public class TypedStatement extends java.lang.ObjectA class that creates a PreparedStatement without having to type native sql code.- Since:
- 1.4.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypedStatement.TypeA list of possible statement types.
-
Constructor Summary
Constructors Constructor Description TypedStatement(DeleteBuilder builder)Creates an DELETE statement.TypedStatement(IndexBuilder builder)Creates a index CREATE statement.TypedStatement(InsertBuilder builder)Creates an INSERT statement.TypedStatement(QueryBuilder builder)Creates a query SELECT statement.TypedStatement(TableBuilder builder)Creates a table CREATE statement.TypedStatement(UpdateBuilder builder)Creates an UPDATE statement.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexecuteCreate()Executes the statement and returns true if no errors occurred.intexecuteInsert()Executes the statement and returns the number of rows updated.longexecuteLargeUpdate()Executes the statement and returns the the number of rows updated.java.sql.ResultSetexecuteQuery()Executes the statement and returns the result-set.intexecuteUpdate()Executes the statement and returns the number of rows updated.java.sql.PreparedStatementgetStatement()Returns thePreparedStatementobject that will generateResultSetobjects for sending SQL statements to the database.TypedStatement.TypegetType()Returns the statement type.static DeleteBuildernewDelete()Creates a new instance of the DeleteBuilder.static IndexBuildernewIndex()Creates a new instance of the IndexBuilder.static InsertBuildernewInsert()Creates a new instance of the InsertBuilder.static QueryBuildernewQuery()Creates a new instance of the QueryBuilder.static TableBuildernewTable()Creates a new instance of the TableBuilder.static UpdateBuildernewUpdate()Creates a new instance of the UpdateBuilder.java.lang.StringtoString()Returns the sql statement as a string.
-
-
-
Constructor Detail
-
TypedStatement
public TypedStatement(QueryBuilder builder) throws java.sql.SQLException
Creates a query SELECT statement.- Parameters:
builder- the QueryBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
TypedStatement
public TypedStatement(UpdateBuilder builder) throws java.sql.SQLException
Creates an UPDATE statement.- Parameters:
builder- the UpdateBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
TypedStatement
public TypedStatement(DeleteBuilder builder) throws java.sql.SQLException
Creates an DELETE statement.- Parameters:
builder- the DeleteBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
TypedStatement
public TypedStatement(InsertBuilder builder) throws java.sql.SQLException
Creates an INSERT statement.- Parameters:
builder- the InsertBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
TypedStatement
public TypedStatement(TableBuilder builder) throws java.sql.SQLException
Creates a table CREATE statement.- Parameters:
builder- the TableBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
TypedStatement
public TypedStatement(IndexBuilder builder) throws java.sql.SQLException
Creates a index CREATE statement.- Parameters:
builder- the IndexBuilder that contains the statement- Throws:
java.sql.SQLException- if a database access error occurs
-
-
Method Detail
-
newQuery
public static QueryBuilder newQuery()
Creates a new instance of the QueryBuilder.- Returns:
- a new instance of the QueryBuilder
-
newUpdate
public static UpdateBuilder newUpdate()
Creates a new instance of the UpdateBuilder.- Returns:
- a new instance of the UpdateBuilder
-
newDelete
public static DeleteBuilder newDelete()
Creates a new instance of the DeleteBuilder.- Returns:
- a new instance of the DeleteBuilder
-
newInsert
public static InsertBuilder newInsert()
Creates a new instance of the InsertBuilder.- Returns:
- a new instance of the InsertBuilder
-
newTable
public static TableBuilder newTable()
Creates a new instance of the TableBuilder.- Returns:
- a new instance of the TableBuilder
-
newIndex
public static IndexBuilder newIndex()
Creates a new instance of the IndexBuilder.- Returns:
- a new instance of the IndexBuilder
-
executeQuery
public java.sql.ResultSet executeQuery() throws java.sql.SQLExceptionExecutes the statement and returns the result-set.- Returns:
- the result of the statement as a
ResultSet - Throws:
java.sql.SQLException- if a database access error occursjava.lang.UnsupportedOperationException- if statement is not a query SELECT statement
-
executeInsert
public int executeInsert() throws java.sql.SQLExceptionExecutes the statement and returns the number of rows updated.- Returns:
- the result of the statement as the number of rows updated
- Throws:
java.sql.SQLException- if a database access error occursjava.lang.UnsupportedOperationException- if statement is not a INSERT statement
-
executeUpdate
public int executeUpdate() throws java.sql.SQLExceptionExecutes the statement and returns the number of rows updated.- Returns:
- the result of the statement as a
ResultSet - Throws:
java.sql.SQLException- if a database access error occursjava.lang.UnsupportedOperationException- if statement is not a UPDATE statement
-
executeLargeUpdate
public long executeLargeUpdate() throws java.sql.SQLExceptionExecutes the statement and returns the the number of rows updated. This method should be used when the returned row count may exceedInteger.MAX_VALUE.- Returns:
- the result of the statement as a
ResultSet - Throws:
java.sql.SQLException- if a database access error occursjava.lang.UnsupportedOperationException- if statement is not a UPDATE statement
-
executeCreate
public boolean executeCreate() throws java.sql.SQLExceptionExecutes the statement and returns true if no errors occurred.- Returns:
- the result of the statement as a boolean, true if no errors occurred
- Throws:
java.sql.SQLException- if a database access error occursjava.lang.UnsupportedOperationException- if statement is not a CREATE statement
-
getStatement
public java.sql.PreparedStatement getStatement()
Returns thePreparedStatementobject that will generateResultSetobjects for sending SQL statements to the database.- Returns:
- the
PreparedStatementobject
-
getType
public TypedStatement.Type getType()
Returns the statement type.- Returns:
- the statement type
-
toString
public java.lang.String toString()
Returns the sql statement as a string.- Overrides:
toStringin classjava.lang.Object- Returns:
- the sql statement as a string
-
-