Class Database.Tasks
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.Database.Tasks
-
- Enclosing class:
- Database
public final class Database.Tasks extends java.lang.Object
The object that stores methods to complete database tasks, useDatabase.getTasks()
to access methods.
-
-
Constructor Summary
Constructors Constructor Description Tasks()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
createIndex(java.lang.String indexName, java.lang.String query, boolean suppressExistsError)
Checks to see if a table index exists and if not, creates it using the specified sql code.boolean
createTable(java.lang.String tableName, java.lang.String query, boolean suppressExistsError)
Checks to see if a table exists and if not, creates it using the specified sql code.boolean
execute(java.lang.String sql)
Executes the given SQL statement, which may return multiple results.java.sql.ResultSet
executeQuery(java.lang.String sql)
Executes the given SQL statement, which returns a singleResultSet
object, auto-closes statement object when ResultSet object is closed.int
executeUpdate(java.lang.String sql)
Executes the given SQL statement, which may be anINSERT
,UPDATE
, orDELETE
statement or an SQL statement that returns nothing, such as an SQL DDL statement.int
getResultRows(java.sql.ResultSet rs)
Returns number of rows that were returned in a ResultSet object.
-
-
-
Method Detail
-
executeQuery
public java.sql.ResultSet executeQuery(java.lang.String sql) throws java.sql.SQLException
Executes the given SQL statement, which returns a singleResultSet
object, auto-closes statement object when ResultSet object is closed.- Parameters:
sql
- an SQL statement to be sent to the database, typically a static SQLSELECT
statement- Returns:
- a
ResultSet
object that contains the data produced by the given query; nevernull
- Throws:
java.sql.SQLException
- if a database access error occurs or the given SQL statement produces anything other than a singleResultSet
object
-
executeUpdate
public int executeUpdate(java.lang.String sql) throws java.sql.SQLException
Executes the given SQL statement, which may be anINSERT
,UPDATE
, orDELETE
statement or an SQL statement that returns nothing, such as an SQL DDL statement.- Parameters:
sql
- an SQL Data Manipulation Language (DML) statement, such asINSERT
,UPDATE
orDELETE
; or an SQL statement that returns nothing, such as a DDL statement.- Returns:
- either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
- Throws:
java.sql.SQLException
- if a database access error occurs or the given SQL statement produces aResultSet
object
-
execute
public boolean execute(java.lang.String sql) throws java.sql.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 methodsgetResultSet
orgetUpdateCount
to retrieve the result, andgetMoreResults
to move to any subsequent result(s).- Parameters:
sql
- any SQL statement- Returns:
true
if the first result is aResultSet
object;false
if it is an update count or there are no results- Throws:
java.sql.SQLException
- if a database access error occurs
-
createTable
public boolean createTable(java.lang.String tableName, java.lang.String query, boolean suppressExistsError) throws java.sql.SQLException
Checks to see if a table exists and if not, creates it using the specified sql code.- Parameters:
tableName
- table name to be createdquery
- sql query to be used to createUser the tablesuppressExistsError
- if true suppresses error if the table already exists- Returns:
- true if created successfully
- Throws:
java.sql.SQLException
- if a database access error occurs
-
createIndex
public boolean createIndex(java.lang.String indexName, java.lang.String query, boolean suppressExistsError) throws java.sql.SQLException
Checks to see if a table index exists and if not, creates it using the specified sql code.- Parameters:
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 exists- Returns:
- true if created successfully
- Throws:
java.sql.SQLException
- if a database access error occurs
-
getResultRows
public int getResultRows(java.sql.ResultSet rs)
Returns number of rows that were returned in a ResultSet object.- Parameters:
rs
- the ResultSet object to count- Returns:
- number of rows in specified ResultSet
-
-