Package adams.db
Interface SQLIntf
-
- All Superinterfaces:
DatabaseConnectionProvider
,DatabaseConnectionUser
,LoggingSupporter
,TableInterface
- All Known Implementing Classes:
AbstractIndexedTable
,AbstractTable
,BulkInsertTable
,LogT
,LogT
,LogT
,LogT
,LogT
,ReportTableByDBID
,ReportTableByID
,SQL
,SQL
,SQLF
public interface SQLIntf extends LoggingSupporter, DatabaseConnectionProvider, TableInterface
Basic SQL support.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description static String
FAKE_TABLE_NAME
fake table name.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
columnExists(String table, String column)
Checks that a given column exists.boolean
drop(String table)
Drops the table.Boolean
execute(String query)
Executes a SQL query.ResultSet
executeGeneratedKeys(String query)
Executes a SQL query.boolean
getDebug()
Returns whether debugging is enabled.int
getMaxColumnNameLength()
Returns the maximum length for column names.ResultSet
getResultSet(String query)
Return resultset of given query.SimpleResultSet
getSimpleResultSet(String query)
Execute the given SQL statement and return ResultSet.PreparedStatement
prepareStatement(String query)
Create a Prepared statement with given query.PreparedStatement
prepareStatement(String query, boolean returnKeys)
Create a Prepared statement with given query.PreparedStatement
prepareStatement(Connection conn, String query, boolean returnKeys)
Create a Prepared statement with given query.ResultSet
select(String columns, String tables, String where)
Do a select on given columns for all data in joined tables, with condition.ResultSet
selectDistinct(String columns, String tables, String where)
Do a select distinct on given columns for all data in joined tables, with condition.gnu.trove.list.TDoubleList
selectDouble(boolean distinct, String column, String tables, String where)
Selects all doubles from the specified column.gnu.trove.list.TIntList
selectInt(boolean distinct, String column, String tables, String where)
Selects all integers from the specified column.gnu.trove.list.TLongList
selectLong(boolean distinct, String column, String tables, String where)
Selects all longs from the specified column.List<String>
selectString(boolean distinct, String column, String tables, String where)
Selects all strings from the specified column.List<String[]>
selectStrings(boolean distinct, String[] columns, String tables, String where)
Selects all strings from the specified columns.void
setDebug(boolean value)
Sets whether debugging is enabled, outputs more on the console.boolean
tableExists(String table)
Checks that a given table exists.boolean
truncate(String table)
Empty table.int
update(String updateString, String table, String where)
Update table.-
Methods inherited from interface adams.db.DatabaseConnectionProvider
getDatabaseConnection
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.db.TableInterface
getTableName
-
-
-
-
Field Detail
-
FAKE_TABLE_NAME
static final String FAKE_TABLE_NAME
fake table name.- See Also:
- Constant Field Values
-
-
Method Detail
-
setDebug
void setDebug(boolean value)
Sets whether debugging is enabled, outputs more on the console.- Parameters:
value
- if true debugging is enabled
-
getDebug
boolean getDebug()
Returns whether debugging is enabled.- Returns:
- true if debugging is enabled
-
tableExists
boolean tableExists(String table)
Checks that a given table exists.- Parameters:
table
- the table to look for- Returns:
- true if the table exists.
-
columnExists
boolean columnExists(String table, String column)
Checks that a given column exists.- Parameters:
table
- the table to searchcolumn
- the column to look for- Returns:
- true if the column exists.
-
getSimpleResultSet
SimpleResultSet getSimpleResultSet(String query) throws Exception
Execute the given SQL statement and return ResultSet.- Parameters:
query
- SQL query String- Returns:
- resulting ResultSet, or null if Error
- Throws:
Exception
- if something goes wrong
-
prepareStatement
PreparedStatement prepareStatement(String query) throws Exception
Create a Prepared statement with given query.- Parameters:
query
- the query to execute- Returns:
- PreparedStatement
- Throws:
Exception
- if something goes wrong
-
prepareStatement
PreparedStatement prepareStatement(String query, boolean returnKeys) throws Exception
Create a Prepared statement with given query.- Parameters:
query
- the query to executereturnKeys
- whether to initialize the statement that it returns the generated keys- Returns:
- PreparedStatement
- Throws:
Exception
- if something goes wrong
-
prepareStatement
PreparedStatement prepareStatement(Connection conn, String query, boolean returnKeys) throws Exception
Create a Prepared statement with given query.- Parameters:
conn
- the database connection to usequery
- the query to executereturnKeys
- whether to initialize the statement that it returns the generated keys- Returns:
- PreparedStatement
- Throws:
Exception
- if something goes wrong
-
update
int update(String updateString, String table, String where) throws Exception
Update table.- Parameters:
updateString
- comma separated updates. e.g weight='80',height=180table
- the table to updatewhere
- condition. e.g name='bob smith'- Returns:
- number of rows affected
- Throws:
Exception
- if something goes wrong
-
executeGeneratedKeys
ResultSet executeGeneratedKeys(String query) throws Exception
Executes a SQL query. Return any Generated Keys Caller is responsible for closing the statement.- Parameters:
query
- the SQL query- Returns:
- Generated keys as a resultset, or null if failure
- Throws:
Exception
- if something goes wrong
-
execute
Boolean execute(String query) throws Exception
Executes a SQL query.- Parameters:
query
- the SQL query- Returns:
- true if the query generated results, false if it didn't, null in case of an error
- Throws:
Exception
- if an error occurs
-
truncate
boolean truncate(String table)
Empty table.- Parameters:
table
- the table to empty- Returns:
- success?
-
drop
boolean drop(String table)
Drops the table.- Parameters:
table
- the table to empty- Returns:
- success?
-
select
ResultSet select(String columns, String tables, String where) throws Exception
Do a select on given columns for all data in joined tables, with condition.- Parameters:
columns
- columns to selecttables
- the tables to select fromwhere
- condition- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectDistinct
ResultSet selectDistinct(String columns, String tables, String where) throws Exception
Do a select distinct on given columns for all data in joined tables, with condition.- Parameters:
columns
- columns to selecttables
- the tables to select fromwhere
- condition- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectString
List<String> selectString(boolean distinct, String column, String tables, String where) throws Exception
Selects all strings from the specified column. Can be distinct.- Parameters:
distinct
- whether values in column have to be distinctcolumn
- the string column to selecttables
- the tables to select from, ignored if nullwhere
- condition, can be null- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectStrings
List<String[]> selectStrings(boolean distinct, String[] columns, String tables, String where) throws Exception
Selects all strings from the specified columns. Can be distinct (uses a CONCAT internally for that).- Parameters:
distinct
- whether values in column have to be distinctcolumns
- the string columns to selecttables
- the tables to select from, ignored if nullwhere
- condition, can be null- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectInt
gnu.trove.list.TIntList selectInt(boolean distinct, String column, String tables, String where) throws Exception
Selects all integers from the specified column. Can be distinct.- Parameters:
distinct
- whether values in column have to be distinctcolumn
- the int column to selecttables
- the tables to select from, ignored if nullwhere
- condition, can be null- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectLong
gnu.trove.list.TLongList selectLong(boolean distinct, String column, String tables, String where) throws Exception
Selects all longs from the specified column. Can be distinct.- Parameters:
distinct
- whether values in column have to be distinctcolumn
- the long column to selecttables
- the tables to select from, ignored if nullwhere
- condition, can be null- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
selectDouble
gnu.trove.list.TDoubleList selectDouble(boolean distinct, String column, String tables, String where) throws Exception
Selects all doubles from the specified column. Can be distinct.- Parameters:
distinct
- whether values in column have to be distinctcolumn
- the long column to selecttables
- the tables to select from, ignored if nullwhere
- condition, can be null- Returns:
- resultset of data
- Throws:
Exception
- if something goes wrong
-
getResultSet
ResultSet getResultSet(String query) throws Exception
Return resultset of given query.- Parameters:
query
- sql query- Returns:
- resulset
- Throws:
Exception
- if something goes wrong
-
getMaxColumnNameLength
int getMaxColumnNameLength() throws SQLException
Returns the maximum length for column names. In case the meta-data returns 0,Integer.MAX_VALUE
is used instead.- Returns:
- the maximum length
- Throws:
SQLException
- if the query fails
-
-