public class SQLHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
DB_PRODUCT_SYBASE
The database product name reported by Sybase JDBC drivers.
|
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areEqualIgnoreNull(String value1,
String value2,
boolean caseSensitive)
Compares the given values and returns true if they are equal.
|
static void |
close(ResultSet resultSet)
Closes the given result set in a null-safe way
|
static void |
close(ResultSet rs,
Statement stmt)
Close a result set and a prepared statement, checking for null references.
|
static void |
close(Statement stmt)
Close a SQL statement, checking for null references.
|
static String |
correctCase(String databaseIdentifier,
Connection connection)
Corrects the case of the given String according to the way in which the database stores metadata.
|
static String |
correctCase(String databaseIdentifier,
DatabaseMetaData databaseMetaData)
Corrects the case of the given String according to the way in which the database stores metadata.
|
static Column |
createColumn(ResultSet resultSet,
IDataTypeFactory dataTypeFactory,
boolean datatypeWarning)
|
static String |
getDatabaseInfo(DatabaseMetaData metaData)
Returns the database and JDBC driver information as pretty formatted string
|
static String |
getPrimaryKeyColumn(Connection conn,
String table)
Gets the primary column for a table.
|
static boolean |
isSybaseDb(DatabaseMetaData metaData)
Detects whether or not the given metadata describes the connection to a Sybase database
or not.
|
static void |
logDebugIfValueChanged(String oldValue,
String newValue,
String message,
Class source)
Checks whether two given values are unequal and if so print a log message (level DEBUG)
|
static void |
logInfoIfValueChanged(String oldValue,
String newValue,
String message,
Class source)
Checks whether two given values are unequal and if so print a log message (level DEBUG)
|
static boolean |
matches(ResultSet resultSet,
String schema,
String table,
boolean caseSensitive)
Deprecated.
|
static boolean |
matches(ResultSet resultSet,
String catalog,
String schema,
String table,
String column,
boolean caseSensitive)
Deprecated.
|
static void |
printAllTables(DatabaseMetaData metaData,
PrintStream outputStream)
Utility method for debugging to print all tables of the given metadata on the given stream
|
static void |
printDatabaseInfo(DatabaseMetaData metaData,
PrintStream outputStream)
Prints the database and JDBC driver information to the given output stream
|
static boolean |
schemaExists(Connection connection,
String schema)
Returns
true if the given schema exists for the given connection. |
static boolean |
tableExists(DatabaseMetaData metaData,
String schema,
String tableName)
Deprecated.
since 2.4.5 - use
IMetadataHandler.tableExists(DatabaseMetaData, String, String) |
public static final String DB_PRODUCT_SYBASE
public static String getPrimaryKeyColumn(Connection conn, String table) throws SQLException
conn - connection with the databasetable - table nameSQLException - raised while getting the meta datapublic static void close(ResultSet rs, Statement stmt) throws SQLException
rs - result set to be closedstmt - prepared statement to be closedSQLException - exception raised in either close() methodpublic static void close(Statement stmt) throws SQLException
stmt - statement to be closedSQLException - exception raised while closing the statementpublic static void close(ResultSet resultSet) throws SQLException
resultSet - SQLExceptionpublic static boolean schemaExists(Connection connection, String schema) throws SQLException
true if the given schema exists for the given connection.connection - The connection to a databaseschema - The schema to be searchedtrue if the given schema exists for the given connection.SQLExceptionpublic static boolean tableExists(DatabaseMetaData metaData, String schema, String tableName) throws SQLException
IMetadataHandler.tableExists(DatabaseMetaData, String, String)metaData - The database meta dataschema - The schema in which the table should be searched. If null
the schema is not used to narrow the table name.tableName - The table name to be searchedtrue if the given table exists in the given schema.
Else returns false.SQLExceptionpublic static void printAllTables(DatabaseMetaData metaData, PrintStream outputStream) throws SQLException
metaData - outputStream - SQLExceptionpublic static String getDatabaseInfo(DatabaseMetaData metaData)
metaData - The JDBC database metadata needed to retrieve database informationpublic static void printDatabaseInfo(DatabaseMetaData metaData, PrintStream outputStream) throws SQLException
metaData - The JDBC database metadata needed to retrieve database informationoutputStream - The stream to which the information is printedSQLExceptionpublic static boolean isSybaseDb(DatabaseMetaData metaData) throws SQLException
metaData - The metadata to be checked whether it is a Sybase connectiontrue if and only if the given metadata belongs to a Sybase database.SQLExceptionpublic static final Column createColumn(ResultSet resultSet, IDataTypeFactory dataTypeFactory, boolean datatypeWarning) throws SQLException, DataTypeException
resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)dataTypeFactory - The factory used to lookup the DataType for this columndatatypeWarning - Whether or not a warning should be printed if the column could not
be created because of an unknown datatype.Column or null if the column could not be initialized because of an
unknown datatype.SQLExceptionDataTypeExceptionpublic static boolean matches(ResultSet resultSet, String schema, String table, boolean caseSensitive) throws SQLException
IMetadataHandler.matches(ResultSet, String, String, String, String, boolean)resultSet matches the given schema and table name.
The comparison is case sensitive.resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)schema - The name of the schema to check. If null it is ignored in the comparisontable - The name of the table to check. If null it is ignored in the comparisoncaseSensitive - Whether or not the comparison should be case sensitive or nottrue if the column metadata of the given resultSet matches
the given schema and table parameters.SQLExceptionpublic static boolean matches(ResultSet resultSet, String catalog, String schema, String table, String column, boolean caseSensitive) throws SQLException
IMetadataHandler.matches(ResultSet, String, String, String, String, boolean)resultSet matches the given schema and table name.
The comparison is case sensitive.resultSet - A result set produced via DatabaseMetaData.getColumns(String, String, String, String)catalog - The name of the catalog to check. If null it is ignored in the comparisonschema - The name of the schema to check. If null it is ignored in the comparisontable - The name of the table to check. If null it is ignored in the comparisoncolumn - The name of the column to check. If null it is ignored in the comparisoncaseSensitive - Whether or not the comparison should be case sensitive or nottrue if the column metadata of the given resultSet matches
the given schema and table parameters.SQLExceptionpublic static final boolean areEqualIgnoreNull(String value1, String value2, boolean caseSensitive)
null or empty String it always
returns true which is the way of ignoring nulls
for this specific case.value1 - The first value to compare. Is ignored if null or empty Stringvalue2 - The second value to be comparedtrue if both values are equal or if the first value
is null or empty string.public static final String correctCase(String databaseIdentifier, Connection connection)
databaseIdentifier - A database identifier such as a table name or a schema name for
which the case should be corrected.connection - The connection used to lookup the database metadata. This is needed to determine
the way in which the database stores its metadata.public static final String correctCase(String databaseIdentifier, DatabaseMetaData databaseMetaData)
databaseIdentifier - A database identifier such as a table name or a schema name for
which the case should be corrected.databaseMetaData - The database metadata needed to determine the way in which the database stores
its metadata.public static final void logInfoIfValueChanged(String oldValue, String newValue, String message, Class source)
oldValue - The old value of a propertynewValue - The new value of a propertymessage - The message to be loggedsource - The class which invokes this method - used for enriching the log messagepublic static final void logDebugIfValueChanged(String oldValue, String newValue, String message, Class source)
oldValue - The old value of a propertynewValue - The new value of a propertymessage - The message to be loggedsource - The class which invokes this method - used for enriching the log messageCopyright © 2002–2025. All rights reserved.