Class Database.Tasks
- java.lang.Object
-
- com.jgcomptech.tools.databasetools.jdbc.Database.Tasks
-
- Enclosing class:
- Database
public final class Database.Tasks extends java.lang.ObjectThe 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 booleancreateIndex(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.booleancreateTable(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.booleanexecute(java.lang.String sql)Executes the given SQL statement, which may return multiple results.java.sql.ResultSetexecuteQuery(java.lang.String sql)Executes the given SQL statement, which returns a singleResultSetobject, auto-closes statement object when ResultSet object is closed.intexecuteUpdate(java.lang.String sql)Executes the given SQL statement, which may be anINSERT,UPDATE, orDELETEstatement or an SQL statement that returns nothing, such as an SQL DDL statement.intgetResultRows(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.SQLExceptionExecutes the given SQL statement, which returns a singleResultSetobject, auto-closes statement object when ResultSet object is closed.- Parameters:
sql- an SQL statement to be sent to the database, typically a static SQLSELECTstatement- Returns:
- a
ResultSetobject 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 singleResultSetobject
-
executeUpdate
public int executeUpdate(java.lang.String sql) throws java.sql.SQLExceptionExecutes the given SQL statement, which may be anINSERT,UPDATE, orDELETEstatement or an SQL statement that returns nothing, such as an SQL DDL statement.- Parameters:
sql- an SQL Data Manipulation Language (DML) statement, such asINSERT,UPDATEorDELETE; 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 aResultSetobject
-
execute
public boolean execute(java.lang.String sql) throws java.sql.SQLExceptionExecutes 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
executemethod executes an SQL statement and indicates the form of the first result. You must then use the methodsgetResultSetorgetUpdateCountto retrieve the result, andgetMoreResultsto move to any subsequent result(s).- Parameters:
sql- any SQL statement- Returns:
trueif the first result is aResultSetobject;falseif 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.SQLExceptionChecks 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.SQLExceptionChecks 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
-
-