Class TypedStatement
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.TypedStatement
-
public class TypedStatement extends java.lang.Object
A 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 class
TypedStatement.Type
A 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 boolean
executeCreate()
Executes the statement and returns true if no errors occurred.int
executeInsert()
Executes the statement and returns the number of rows updated.long
executeLargeUpdate()
Executes the statement and returns the the number of rows updated.java.sql.ResultSet
executeQuery()
Executes the statement and returns the result-set.int
executeUpdate()
Executes the statement and returns the number of rows updated.java.sql.PreparedStatement
getStatement()
Returns thePreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.TypedStatement.Type
getType()
Returns the statement type.static DeleteBuilder
newDelete()
Creates a new instance of the DeleteBuilder.static IndexBuilder
newIndex()
Creates a new instance of the IndexBuilder.static InsertBuilder
newInsert()
Creates a new instance of the InsertBuilder.static QueryBuilder
newQuery()
Creates a new instance of the QueryBuilder.static TableBuilder
newTable()
Creates a new instance of the TableBuilder.static UpdateBuilder
newUpdate()
Creates a new instance of the UpdateBuilder.java.lang.String
toString()
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.SQLException
Executes 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.SQLException
Executes 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.SQLException
Executes 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.SQLException
Executes 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.SQLException
Executes 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 thePreparedStatement
object that will generateResultSet
objects for sending SQL statements to the database.- Returns:
- the
PreparedStatement
object
-
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:
toString
in classjava.lang.Object
- Returns:
- the sql statement as a string
-
-