public class JDBCUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static SQLDialect |
dialect(java.sql.Connection connection)
"Guess" the
SQLDialect from a Connection instance. |
static SQLDialect |
dialect(java.lang.String url)
"Guess" the
SQLDialect from a connection URL. |
static java.lang.String |
driver(java.lang.String url)
"Guess" the JDBC driver from a connection URL.
|
static void |
safeClose(java.sql.Connection connection)
Safely close a connection.
|
static void |
safeClose(java.sql.ResultSet resultSet)
Safely close a result set.
|
static void |
safeClose(java.sql.ResultSet resultSet,
java.sql.PreparedStatement statement)
Safely close a result set and / or a statement.
|
static void |
safeClose(java.sql.Statement statement)
Safely close a statement.
|
static void |
safeFree(java.sql.Array array)
Safely free an Array object.
|
static void |
safeFree(java.sql.Blob blob)
Safely free a blob.
|
static void |
safeFree(java.sql.Clob clob)
Safely free a clob.
|
static void |
safeFree(java.sql.SQLXML xml)
Safely free an XML object.
|
static java.lang.Boolean |
wasNull(java.sql.CallableStatement statement,
java.lang.Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(java.sql.CallableStatement statement,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends java.lang.Number> |
wasNull(java.sql.CallableStatement statement,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static java.lang.Boolean |
wasNull(java.sql.ResultSet rs,
java.lang.Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(java.sql.ResultSet rs,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends java.lang.Number> |
wasNull(java.sql.ResultSet rs,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static java.lang.Boolean |
wasNull(java.sql.SQLInput stream,
java.lang.Boolean value)
Convenient way to check if a JDBC-originated record was
null . |
static <T> T |
wasNull(java.sql.SQLInput stream,
T value)
Convenient way to check if a JDBC-originated record was
null . |
static <T extends java.lang.Number> |
wasNull(java.sql.SQLInput stream,
T value)
Convenient way to check if a JDBC-originated record was
null . |
public static final SQLDialect dialect(java.sql.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(java.lang.String url)
SQLDialect
from a connection URL.public static final java.lang.String driver(java.lang.String url)
public static final void safeClose(java.sql.Connection connection)
This method will silently ignore if connection
is
null
, or if Connection.close()
throws an exception.
public static final void safeClose(java.sql.Statement statement)
This method will silently ignore if statement
is
null
, or if Statement.close()
throws an exception.
public static final void safeClose(java.sql.ResultSet resultSet)
This method will silently ignore if resultSet
is
null
, or if ResultSet.close()
throws an exception.
public static final void safeClose(java.sql.ResultSet resultSet, java.sql.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(java.sql.Blob blob)
This method will silently ignore if blob
is
null
, or if Blob.free()
throws an exception.
public static final void safeFree(java.sql.Clob clob)
This method will silently ignore if clob
is
null
, or if Clob.free()
throws an exception.
public static final void safeFree(java.sql.SQLXML xml)
This method will silently ignore if xml
is
null
, or if SQLXML.free()
throws an exception.
public static final void safeFree(java.sql.Array array)
This method will silently ignore if array
is
null
, or if Array.free()
throws an exception.
public static final <T> T wasNull(java.sql.SQLInput stream, T value) throws java.sql.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
java.sql.SQLException
public static final <T extends java.lang.Number> T wasNull(java.sql.SQLInput stream, T value) throws java.sql.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
java.sql.SQLException
public static final java.lang.Boolean wasNull(java.sql.SQLInput stream, java.lang.Boolean value) throws java.sql.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
java.sql.SQLException
public static final <T> T wasNull(java.sql.ResultSet rs, T value) throws java.sql.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
java.sql.SQLException
public static final <T extends java.lang.Number> T wasNull(java.sql.ResultSet rs, T value) throws java.sql.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
java.sql.SQLException
public static final java.lang.Boolean wasNull(java.sql.ResultSet rs, java.lang.Boolean value) throws java.sql.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
java.sql.SQLException
public static final <T> T wasNull(java.sql.CallableStatement statement, T value) throws java.sql.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
java.sql.SQLException
public static final <T extends java.lang.Number> T wasNull(java.sql.CallableStatement statement, T value) throws java.sql.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
java.sql.SQLException
public static final java.lang.Boolean wasNull(java.sql.CallableStatement statement, java.lang.Boolean value) throws java.sql.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
java.sql.SQLException
Copyright © 2018. All Rights Reserved.