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 String |
driver(String url)
"Guess" the JDBC driver 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(Array array)
Safely free an Array object.
|
static void |
safeFree(Blob blob)
Safely free a blob.
|
static void |
safeFree(Clob clob)
Safely free a clob.
|
static void |
safeFree(SQLXML xml)
Safely free an XML object.
|
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.
SQLDialect or SQLDialect.DEFAULT
if no dialect could be derived from the connection. Never
null.dialect(String)public static final SQLDialect dialect(String url)
SQLDialect from a connection URL.SQLDialect or SQLDialect.DEFAULT
if no dialect could be derived from the connection. Never
null.public static final String driver(String url)
"java.sql.Driver" if no driver class could be
derived from the URL. Never null.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 void safeFree(SQLXML xml)
This method will silently ignore if xml is
null, or if SQLXML.free() throws an exception.
public static final void safeFree(Array array)
This method will silently ignore if array is
null, or if Array.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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionpublic 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 trueSQLExceptionCopyright © 2019. All rights reserved.