- java.lang.Object
-
- org.jooq.tools.jdbc.JDBCUtils
-
public class JDBCUtils extends Object
JDBC-related utility methods.- Author:
- Lukas Eder
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull SQLDialectdialect(String url)"Guess" theSQLDialectfrom a connection URL.static @NotNull SQLDialectdialect(Connection connection)"Guess" theSQLDialectfrom aConnectioninstance.static @NotNull Stringdriver(String url)"Guess" the JDBC driver from a connection URL.static @NotNull Stringdriver(SQLDialect dialect)"Guess" the JDBC driver from aSQLDialect.static voidsafeClose(Closeable closeable)Safely close a closeable.static voidsafeClose(AutoCloseable closeable)Safely close a closeable.static voidsafeClose(Connection connection)Safely close a connection.static voidsafeClose(ResultSet resultSet)Safely close a result set.static voidsafeClose(ResultSet resultSet, PreparedStatement statement)Safely close a result set and / or a statement.static voidsafeClose(Statement statement)Safely close a statement.static voidsafeFree(Array array)Safely free an Array object.static voidsafeFree(Blob blob)Safely free a blob.static voidsafeFree(Clob clob)Safely free a clob.static voidsafeFree(SQLXML xml)Safely free an XML object.static BooleanwasNull(CallableStatement statement, Boolean value)Convenient way to check if a JDBC-originated record wasnull.static <T> TwasNull(CallableStatement statement, T value)Convenient way to check if a JDBC-originated record wasnull.static BooleanwasNull(ResultSet rs, Boolean value)Convenient way to check if a JDBC-originated record wasnull.static <T> TwasNull(ResultSet rs, T value)Convenient way to check if a JDBC-originated record wasnull.static BooleanwasNull(SQLInput stream, Boolean value)Convenient way to check if a JDBC-originated record wasnull.static <T> TwasNull(SQLInput stream, T value)Convenient way to check if a JDBC-originated record wasnull.
-
-
-
Method Detail
-
dialect
@NotNull public static final @NotNull SQLDialect dialect(Connection connection)
"Guess" theSQLDialectfrom aConnectioninstance.This method tries to guess the
SQLDialectof a connection from the its connection URL as obtained byDatabaseMetaData.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.- Returns:
- The appropriate
SQLDialectorSQLDialect.DEFAULTif no dialect could be derived from the connection. Nevernull. - See Also:
dialect(String)
-
dialect
@NotNull public static final @NotNull SQLDialect dialect(String url)
"Guess" theSQLDialectfrom a connection URL.- Returns:
- The appropriate
SQLDialectorSQLDialect.DEFAULTif no dialect could be derived from the connection. Nevernull.
-
driver
@NotNull public static final @NotNull String driver(SQLDialect dialect)
"Guess" the JDBC driver from aSQLDialect.- Returns:
- The appropriate JDBC driver class or
"java.sql.Driver"if no driver class could be derived from the URL. Nevernull.
-
driver
@NotNull public static final @NotNull String driver(String url)
"Guess" the JDBC driver from a connection URL.- Returns:
- The appropriate JDBC driver class or
"java.sql.Driver"if no driver class could be derived from the URL. Nevernull.
-
safeClose
public static final void safeClose(Connection connection)
Safely close a connection.This method will silently ignore if
connectionisnull, or ifConnection.close()throws an exception.
-
safeClose
public static final void safeClose(Statement statement)
Safely close a statement.This method will silently ignore if
statementisnull, or ifStatement.close()throws an exception.
-
safeClose
public static final void safeClose(ResultSet resultSet)
Safely close a result set.This method will silently ignore if
resultSetisnull, or ifResultSet.close()throws an exception.
-
safeClose
public static final void safeClose(ResultSet resultSet, PreparedStatement statement)
Safely close a result set and / or a statement.This method will silently ignore if
resultSetorstatementisnull, or ifResultSet.close()orStatement.close()throws an exception.
-
safeClose
public static final void safeClose(Closeable closeable)
Safely close a closeable.This method will silently ignore if
closeableisnull, or ifCloseable.close()throws an exception.
-
safeClose
public static final void safeClose(AutoCloseable closeable)
Safely close a closeable.This method will silently ignore if
closeableisnull, or ifAutoCloseable.close()throws an exception.
-
safeFree
public static final void safeFree(Blob blob)
Safely free a blob.This method will silently ignore if
blobisnull, or ifBlob.free()throws an exception.
-
safeFree
public static final void safeFree(Clob clob)
Safely free a clob.This method will silently ignore if
clobisnull, or ifClob.free()throws an exception.
-
safeFree
public static final void safeFree(SQLXML xml)
Safely free an XML object.This method will silently ignore if
xmlisnull, or ifSQLXML.free()throws an exception.
-
safeFree
public static final void safeFree(Array array)
Safely free an Array object.This method will silently ignore if
arrayisnull, or ifArray.free()throws an exception.
-
wasNull
public static final <T> T wasNull(SQLInput stream, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
stream- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theSQLInput.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final <T extends Number> T wasNull(SQLInput stream, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
stream- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theSQLInput.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final Boolean wasNull(SQLInput stream, Boolean value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
stream- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theSQLInput.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final <T> T wasNull(ResultSet rs, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
rs- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theResultSet.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final <T extends Number> T wasNull(ResultSet rs, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
rs- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theResultSet.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final Boolean wasNull(ResultSet rs, Boolean value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
rs- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theResultSet.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final <T> T wasNull(CallableStatement statement, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
statement- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theCallableStatement.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final <T extends Number> T wasNull(CallableStatement statement, T value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
statement- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theCallableStatement.wasNull()istrue - Throws:
SQLException
-
wasNull
public static final Boolean wasNull(CallableStatement statement, Boolean value) throws SQLException
Convenient way to check if a JDBC-originated record wasnull.This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.
- Parameters:
statement- The data source from which a value was readvalue- The value that was read- Returns:
- The
valueornullif theCallableStatement.wasNull()istrue - Throws:
SQLException
-
-