Package liquibase.util
Class JdbcUtil
- java.lang.Object
-
- liquibase.util.JdbcUtil
-
-
Field Summary
Fields Modifier and Type Field Description static intTYPE_UNKNOWNConstant that indicates an unknown (or unspecified) SQL type.
-
Constructor Summary
Constructors Constructor Description JdbcUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclose(ResultSet rs, Statement stmt)static voidcloseResultSet(ResultSet rs)Close the given JDBC ResultSet and ignore any thrown exception.static voidcloseStatement(Statement stmt)Close the given JDBC Statement and ignore any thrown exception.static ObjectgetResultSetValue(ResultSet rs, int index)Retrieve a JDBC column value from a ResultSet, using the most appropriate value type.static StringgetValueForColumn(ResultSet rs, String columnNameToCheck, Database database)Checks whether a result set has a column matching the specified column name.static booleanisNumeric(int sqlType)Check whether the given SQL type is numeric.static ObjectrequiredSingleResult(Collection results)Return a single result object from the given Collection.
-
-
-
Field Detail
-
TYPE_UNKNOWN
public static final int TYPE_UNKNOWN
Constant that indicates an unknown (or unspecified) SQL type.- See Also:
Types, Constant Field Values
-
-
Method Detail
-
closeStatement
public static void closeStatement(Statement stmt)
Close the given JDBC Statement and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.- Parameters:
stmt- the JDBC Statement to close (may benull)
-
closeResultSet
public static void closeResultSet(ResultSet rs)
Close the given JDBC ResultSet and ignore any thrown exception. This is useful for typical finally blocks in manual JDBC code.- Parameters:
rs- the JDBC ResultSet to close (may benull)
-
getResultSetValue
public static Object getResultSetValue(ResultSet rs, int index) throws SQLException
Retrieve a JDBC column value from a ResultSet, using the most appropriate value type. The returned value should be a detached value object, not having any ties to the active ResultSet: in particular, it should not be a Blob or Clob object but rather a byte array respectively String representation.Uses the
getObject(index)method, but includes additional "hacks" to get around Oracle 10g returning a non-standard object for its TIMESTAMP datatype and ajava.sql.Datefor DATE columns leaving out the time portion: These columns will explicitly be extracted as standardjava.sql.Timestampobject.- Parameters:
rs- is the ResultSet holding the dataindex- is the column index- Returns:
- the value object
- Throws:
SQLException- if thrown by the JDBC API- See Also:
Blob,Clob,Timestamp
-
isNumeric
public static boolean isNumeric(int sqlType)
Check whether the given SQL type is numeric.- Parameters:
sqlType- the SQL type to be checked- Returns:
- whether the type is numeric
-
requiredSingleResult
public static Object requiredSingleResult(Collection results) throws DatabaseException
Return a single result object from the given Collection.Throws an exception if 0 or more than 1 element found.
- Parameters:
results- the result Collection (can benull)- Returns:
- the single result object
- Throws:
DatabaseException
-
getValueForColumn
public static String getValueForColumn(ResultSet rs, String columnNameToCheck, Database database) throws SQLException
Checks whether a result set has a column matching the specified column name. The column name is first changed to match the database format. E.g. an unquoted columnName in h2 will be converted to uppercase so the column name that is being checked for is really the uppercase version of the column name,- Parameters:
rs- result set to checkcolumnNameToCheck- column name to check- Returns:
- The value if found, null if not found
- Throws:
SQLException
-
-