Top Fields Constructors Methods
liquibase.util

public abstract Class JdbcUtil

extends Object
Class Inheritance
Known Direct Subclasses
liquibase.util.JdbcUtils
Imports
liquibase.database.Database, liquibase.exception.DatabaseException, liquibase.structure.core.Column, java.sql.*, java.util.Collection

Field Summary

Modifier and TypeField and Description
public static final int
TYPE_UNKNOWN

Constant that indicates an unknown (or unspecified) SQL type.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
public static void
closeResultSet(ResultSet
the JDBC ResultSet to close (may be null)
rs
)

Close the given JDBC ResultSet and ignore any thrown exception.

public static void
closeStatement(Statement
the JDBC Statement to close (may be null)
stmt
)

Close the given JDBC Statement and ignore any thrown exception.

public static Object

Returns:

the value object
getResultSetValue
(ResultSet
is the ResultSet holding the data
rs
,
int
is the column index
index
)

Retrieve a JDBC column value from a ResultSet, using the most appropriate value type.

public static String

Returns:

The value if found, null if not found
getValueForColumn
(ResultSet
result set to check
rs
,
String
column name to check
columnNameToCheck
,
Database database)

Checks whether a result set has a column matching the specified column name.

public static boolean

Returns:

whether the type is numeric
isNumeric
(int
the SQL type to be checked
sqlType
)

Check whether the given SQL type is numeric.

public static Object

Returns:

the single result object
requiredSingleResult
(Collection<E>
the result Collection (can be null)
results
)

Return a single result object from the given Collection.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

TYPE_UNKNOWNback to summary
public static final int TYPE_UNKNOWN

Constant that indicates an unknown (or unspecified) SQL type.

See Also
java.sql.Types

Constructor Detail

JdbcUtilback to summary
public JdbcUtil()

Method Detail

closeback to summary
public static void close(ResultSet rs, Statement stmt)
closeResultSetback to summary
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:ResultSet

the JDBC ResultSet to close (may be null)

closeStatementback to summary
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:Statement

the JDBC Statement to close (may be null)

getResultSetValueback to summary
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 a java.sql.Date for DATE columns leaving out the time portion: These columns will explicitly be extracted as standard java.sql.Timestamp object.

Parameters
rs:ResultSet

is the ResultSet holding the data

index:int

is the column index

Returns:Object

the value object

Exceptions
SQLException:
if thrown by the JDBC API
See Also
java.sql.Blob, java.sql.Clob, java.sql.Timestamp
getValueForColumnback to summary
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:ResultSet

result set to check

columnNameToCheck:String

column name to check

Returns:String

The value if found, null if not found

isNumericback to summary
public static boolean isNumeric(int sqlType)

Check whether the given SQL type is numeric.

Parameters
sqlType:int

the SQL type to be checked

Returns:boolean

whether the type is numeric

requiredSingleResultback to summary
public static Object requiredSingleResult(Collection<E> 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:Collection<E>

the result Collection (can be null)

Returns:Object

the single result object