public final class Database.Tasks extends Object
The object that stores methods to complete database tasks, use Database.getTasks()
to access methods.
Constructor and Description |
---|
Tasks() |
Modifier and Type | Method and Description |
---|---|
boolean |
createIndex(String indexName,
String query,
boolean suppressExistsError)
Checks to see if a table index exists and if not, creates it using the specified sql code.
|
boolean |
createTable(String tableName,
String query,
boolean suppressExistsError)
Checks to see if a table exists and if not, creates it using the specified sql code.
|
boolean |
execute(String sql)
Executes the given SQL statement, which may return multiple results.
|
ResultSet |
executeQuery(String sql)
Executes the given SQL statement, which returns a single
ResultSet object, auto-closes statement object when ResultSet object is closed. |
int |
executeUpdate(String sql)
Executes the given SQL statement, which may be an
INSERT , UPDATE , or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement. |
int |
getResultRows(ResultSet rs)
Returns number of rows that were returned in a ResultSet object.
|
public ResultSet executeQuery(String sql) throws SQLException
Executes the given SQL statement, which returns a single ResultSet
object, auto-closes statement object when ResultSet object is closed.
sql
- an SQL statement to be sent to the database, typically a static SQL SELECT
statementResultSet
object that contains the data produced by the given query; never null
SQLException
- if a database access error occurs or the given SQL statement produces anything other than a single ResultSet
objectpublic int executeUpdate(String sql) throws SQLException
Executes the given SQL statement, which may be an INSERT
, UPDATE
, or DELETE
statement or an SQL statement that returns nothing, such as an SQL DDL statement.
sql
- an SQL Data Manipulation Language (DML) statement, such as INSERT
, UPDATE
or DELETE
; or an SQL statement that returns nothing, such as a DDL statement.SQLException
- if a database access error occurs or the given SQL statement produces a ResultSet
objectpublic boolean execute(String sql) throws SQLException
Executes the given SQL statement, which may return multiple results. In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.
The execute
method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet
or getUpdateCount
to retrieve the result, and getMoreResults
to move to any subsequent result(s).
sql
- any SQL statementtrue
if the first result is a ResultSet
object; false
if it is an update count or there are no resultsSQLException
- if a database access error occurspublic boolean createTable(String tableName, String query, boolean suppressExistsError) throws SQLException
Checks to see if a table exists and if not, creates it using the specified sql code.
tableName
- table name to be createdquery
- sql query to be used to createUser the tablesuppressExistsError
- if true suppresses error if the table already existsSQLException
- if a database access error occurspublic boolean createIndex(String indexName, String query, boolean suppressExistsError) throws SQLException
Checks to see if a table index exists and if not, creates it using the specified sql code.
indexName
- index name to be createdquery
- sql query to be used to createUser the table indexsuppressExistsError
- if true suppresses error if the table index already existsSQLException
- if a database access error occurspublic int getResultRows(ResultSet rs)
Returns number of rows that were returned in a ResultSet object.
rs
- the ResultSet object to countCopyright © 2017–2018 J&G CompTech. All rights reserved.