public class JDBCUtils extends Object
Modifier and Type | Method and Description |
---|---|
static SQLDialect |
dialect(Connection connection)
"Guess" the
SQLDialect from a Connection instance. |
static SQLDialect |
dialect(String url)
"Guess" the
SQLDialect from a connection URL. |
static void |
safeClose(Connection connection)
Safely close a connection.
|
static void |
safeClose(ResultSet resultSet)
Safely close a result set.
|
static void |
safeClose(ResultSet resultSet,
PreparedStatement statement)
Safely close a result set and / or a statement.
|
static void |
safeClose(Statement statement)
Safely close a statement.
|
static void |
safeFree(Blob blob)
Safely free a blob.
|
static void |
safeFree(Clob clob)
Safely free a clob.
|
static Boolean |
wasNull(CallableStatement statement,
Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(CallableStatement statement,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends Number> |
wasNull(CallableStatement statement,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static Boolean |
wasNull(ResultSet rs,
Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(ResultSet rs,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends Number> |
wasNull(ResultSet rs,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static Boolean |
wasNull(SQLInput stream,
Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(SQLInput stream,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends Number> |
wasNull(SQLInput stream,
T value)
Convenient way to check if a JDBC-originated record was
null . |
public static final SQLDialect dialect(Connection connection)
SQLDialect
from a Connection
instance.
This method tries to guess the SQLDialect
of a connection
from the its connection URL as obtained by
DatabaseMetaData.getURL()
. If the dialect cannot be guessed from
the URL (e.g. when using an JDBC-ODBC bridge), further actions may be
implemented in the future.
dialect(String)
public static final SQLDialect dialect(String url)
SQLDialect
from a connection URL.public static final void safeClose(Connection connection)
This method will silently ignore if connection
is
null
, or if Connection.close()
throws an exception.
public static final void safeClose(Statement statement)
This method will silently ignore if statement
is
null
, or if Statement.close()
throws an exception.
public static final void safeClose(ResultSet resultSet)
This method will silently ignore if resultSet
is
null
, or if ResultSet.close()
throws an exception.
public static final void safeClose(ResultSet resultSet, PreparedStatement statement)
This method will silently ignore if resultSet
or
statement
is null
, or if
ResultSet.close()
or Statement.close()
throws an
exception.
public static final void safeFree(Blob blob)
This method will silently ignore if blob
is
null
, or if Blob.free()
throws an exception.
public static final void safeFree(Clob clob)
This method will silently ignore if clob
is
null
, or if Clob.free()
throws an exception.
public static final <T> T wasNull(SQLInput stream, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
stream
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
SQLInput.wasNull()
is true
SQLException
public static final <T extends Number> T wasNull(SQLInput stream, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
stream
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
SQLInput.wasNull()
is true
SQLException
public static final Boolean wasNull(SQLInput stream, Boolean value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
stream
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
SQLInput.wasNull()
is true
SQLException
public static final <T> T wasNull(ResultSet rs, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
rs
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
ResultSet.wasNull()
is true
SQLException
public static final <T extends Number> T wasNull(ResultSet rs, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
rs
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
ResultSet.wasNull()
is true
SQLException
public static final Boolean wasNull(ResultSet rs, Boolean value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
rs
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
ResultSet.wasNull()
is true
SQLException
public static final <T> T wasNull(CallableStatement statement, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
statement
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
CallableStatement.wasNull()
is true
SQLException
public static final <T extends Number> T wasNull(CallableStatement statement, T value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
statement
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
CallableStatement.wasNull()
is true
SQLException
public static final Boolean wasNull(CallableStatement statement, Boolean value) throws SQLException
null
.
This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
statement
- The data source from which a value was readvalue
- The value that was readvalue
or null
if the
CallableStatement.wasNull()
is true
SQLException
Copyright © 2015. All Rights Reserved.