Top Description Fields Constructors Methods
org.jooq.tools.jdbc

public Class JDBCUtils

extends Object
Class Inheritance
Static Imports
org.jooq.SQLDialect.*

JDBC-related utility methods.
Author
Lukas Eder

Field Summary

Modifier and TypeField and Description
private static final JooqLogger

Constructor Summary

AccessConstructor and Description
private
JDBCUtils()

No instances.

Method Summary

Modifier and TypeMethod and Description
public static final @NotNull SQLDialect

Returns:

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.
dialect
(Connection connection)

"Guess" the SQLDialect from a Connection instance.

public static final @NotNull SQLDialect

Returns:

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.
dialect
(ConnectionFactory connection)

"Guess" the SQLDialect from a ConnectionFactory instance.

public static final @NotNull SQLDialect

Returns:

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.
dialect
(Connection connection)

"Guess" the SQLDialect from an R2DBC io.r2dbc.spi.Connection instance.

private static final @NotNull SQLDialect
dialect(String url, int majorVersion, int minorVersion, String productVersion)

public static final @NotNull SQLDialect

Returns:

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.
dialect
(String url)

"Guess" the SQLDialect from a connection URL.

private static SQLDialect
public static final @NotNull String

Returns:

The appropriate JDBC driver class or "java.sql.Driver" if no driver class could be derived from the URL. Never null.
driver
(SQLDialect dialect)

"Guess" the JDBC driver from a SQLDialect.

public static final @NotNull String

Returns:

The appropriate JDBC driver class or "java.sql.Driver" if no driver class could be derived from the URL. Never null.
driver
(String url)

"Guess" the JDBC driver from a connection URL.

private static final SQLDialect
firebirdDialect(int majorVersion)

private static final SQLDialect
h2Dialect(int majorVersion, int minorVersion, String productVersion)

private static final SQLDialect
mariadbDialect(int majorVersion, int minorVersion)

private static final SQLDialect
mysqlDialect(int majorVersion, int minorVersion, String productVersion)

private static final SQLDialect
postgresDialect(int majorVersion, int minorVersion)

public static final void
safeClose(Connection connection)

Safely close a connection.

public static final void
safeClose(Statement statement)

Safely close a statement.

public static final void
safeClose(ResultSet resultSet)

Safely close a result set.

public static final void
safeClose(ResultSet resultSet, PreparedStatement statement)

Safely close a result set and / or a statement.

public static final void
safeClose(Closeable closeable)

Safely close a closeable.

public static final void
safeClose(AutoCloseable closeable)

Safely close a closeable.

public static final void
safeFree(Blob blob)

Safely free a blob.

public static final void
safeFree(Clob clob)

Safely free a clob.

public static final void
safeFree(SQLXML xml)

Safely free an XML object.

public static final void
safeFree(Array array)

Safely free an Array object.

public static final <T> T

Returns:

The value or null if the SQLInput#wasNull() is true
wasNull
(SQLInput
The data source from which a value was read
stream
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final <T extends Number> T

Returns:

The value or null if the SQLInput#wasNull() is true
wasNull
(SQLInput
The data source from which a value was read
stream
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final Boolean

Returns:

The value or null if the SQLInput#wasNull() is true
wasNull
(SQLInput
The data source from which a value was read
stream
,
Boolean
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final <T> T

Returns:

The value or null if the ResultSet#wasNull() is true
wasNull
(ResultSet
The data source from which a value was read
rs
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final <T extends Number> T

Returns:

The value or null if the ResultSet#wasNull() is true
wasNull
(ResultSet
The data source from which a value was read
rs
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final Boolean

Returns:

The value or null if the ResultSet#wasNull() is true
wasNull
(ResultSet
The data source from which a value was read
rs
,
Boolean
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final <T> T

Returns:

The value or null if the CallableStatement#wasNull() is true
wasNull
(CallableStatement
The data source from which a value was read
statement
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final <T extends Number> T

Returns:

The value or null if the CallableStatement#wasNull() is true
wasNull
(CallableStatement
The data source from which a value was read
statement
,
T
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

public static final Boolean

Returns:

The value or null if the CallableStatement#wasNull() is true
wasNull
(CallableStatement
The data source from which a value was read
statement
,
Boolean
The value that was read
value
)

Convenient way to check if a JDBC-originated record was null.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logback to summary
private static final JooqLogger log

Constructor Detail

JDBCUtilsback to summary
private JDBCUtils()

No instances.

Method Detail

dialectback to summary
public static final @NotNull SQLDialect dialect(Connection connection)

"Guess" the 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.

Returns:@NotNull SQLDialect

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.

Annotations
@NotNull
See Also
dialect(String)
dialectback to summary
public static final @NotNull SQLDialect dialect(ConnectionFactory connection)

"Guess" the SQLDialect from a ConnectionFactory instance.

This method tries to guess the SQLDialect of a connection from the its ConnectionFactoryMetadata as obtained by ConnectionFactory#getMetadata(). If the dialect cannot be guessed, further actions may be implemented in the future.

Returns:@NotNull SQLDialect

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.

Annotations
@NotNull
See Also
dialect(String)
dialectback to summary
public static final @NotNull SQLDialect dialect(Connection connection)

"Guess" the SQLDialect from an R2DBC io.r2dbc.spi.Connection instance.

This method tries to guess the SQLDialect of a connection from the its ConnectionMetadata as obtained by io.r2dbc.spi.Connection#getMetadata(). If the dialect cannot be, further actions may be implemented in the future.

Returns:@NotNull SQLDialect

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.

Annotations
@NotNull
See Also
dialect(String)
dialectback to summary
private static final @NotNull SQLDialect dialect(String url, int majorVersion, int minorVersion, String productVersion)
Annotations
@NotNull
dialectback to summary
public static final @NotNull SQLDialect dialect(String url)

"Guess" the SQLDialect from a connection URL.

Returns:@NotNull SQLDialect

The appropriate SQLDialect or SQLDialect#DEFAULT if no dialect could be derived from the connection. Never null.

Annotations
@NotNull
dialectFromProductNameback to summary
private static SQLDialect dialectFromProductName(String product)
driverback to summary
public static final @NotNull String driver(SQLDialect dialect)

"Guess" the JDBC driver from a SQLDialect.

Returns:@NotNull String

The appropriate JDBC driver class or "java.sql.Driver" if no driver class could be derived from the URL. Never null.

Annotations
@NotNull
driverback to summary
public static final @NotNull String driver(String url)

"Guess" the JDBC driver from a connection URL.

Returns:@NotNull String

The appropriate JDBC driver class or "java.sql.Driver" if no driver class could be derived from the URL. Never null.

Annotations
@NotNull
firebirdDialectback to summary
private static final SQLDialect firebirdDialect(int majorVersion)
h2Dialectback to summary
private static final SQLDialect h2Dialect(int majorVersion, int minorVersion, String productVersion)
mariadbDialectback to summary
private static final SQLDialect mariadbDialect(int majorVersion, int minorVersion)
mysqlDialectback to summary
private static final SQLDialect mysqlDialect(int majorVersion, int minorVersion, String productVersion)
postgresDialectback to summary
private static final SQLDialect postgresDialect(int majorVersion, int minorVersion)
safeCloseback to summary
public static final void safeClose(Connection connection)

Safely close a connection.

This method will silently ignore if connection is null, or if Connection#close() throws an exception.

safeCloseback to summary
public static final void safeClose(Statement statement)

Safely close a statement.

This method will silently ignore if statement is null, or if Statement#close() throws an exception.

safeCloseback to summary
public static final void safeClose(ResultSet resultSet)

Safely close a result set.

This method will silently ignore if resultSet is null, or if ResultSet#close() throws an exception.

safeCloseback to summary
public static final void safeClose(ResultSet resultSet, PreparedStatement statement)

Safely close a result set and / or a statement.

This method will silently ignore if resultSet or statement is null, or if ResultSet#close() or Statement#close() throws an exception.

safeCloseback to summary
public static final void safeClose(Closeable closeable)

Safely close a closeable.

This method will silently ignore if closeable is null, or if Closeable#close() throws an exception.

safeCloseback to summary
public static final void safeClose(AutoCloseable closeable)

Safely close a closeable.

This method will silently ignore if closeable is null, or if AutoCloseable#close() throws an exception.

safeFreeback to summary
public static final void safeFree(Blob blob)

Safely free a blob.

This method will silently ignore if blob is null, or if Blob#free() throws an exception.

safeFreeback to summary
public static final void safeFree(Clob clob)

Safely free a clob.

This method will silently ignore if clob is null, or if Clob#free() throws an exception.

safeFreeback to summary
public static final void safeFree(SQLXML xml)

Safely free an XML object.

This method will silently ignore if xml is null, or if SQLXML#free() throws an exception.

safeFreeback to summary
public static final void safeFree(Array array)

Safely free an Array object.

This method will silently ignore if array is null, or if Array#free() throws an exception.

wasNullback to summary
public static final <T> T wasNull(SQLInput stream, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
stream:SQLInput

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the SQLInput#wasNull() is true

wasNullback to summary
public static final <T extends Number> T wasNull(SQLInput stream, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
stream:SQLInput

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the SQLInput#wasNull() is true

wasNullback to summary
public static final Boolean wasNull(SQLInput stream, Boolean value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
stream:SQLInput

The data source from which a value was read

value:Boolean

The value that was read

Returns:Boolean

The value or null if the SQLInput#wasNull() is true

wasNullback to summary
public static final <T> T wasNull(ResultSet rs, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
rs:ResultSet

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the ResultSet#wasNull() is true

wasNullback to summary
public static final <T extends Number> T wasNull(ResultSet rs, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
rs:ResultSet

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the ResultSet#wasNull() is true

wasNullback to summary
public static final Boolean wasNull(ResultSet rs, Boolean value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
rs:ResultSet

The data source from which a value was read

value:Boolean

The value that was read

Returns:Boolean

The value or null if the ResultSet#wasNull() is true

wasNullback to summary
public static final <T> T wasNull(CallableStatement statement, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
statement:CallableStatement

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the CallableStatement#wasNull() is true

wasNullback to summary
public static final <T extends Number> T wasNull(CallableStatement statement, T value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
statement:CallableStatement

The data source from which a value was read

value:T

The value that was read

Returns:T

The value or null if the CallableStatement#wasNull() is true

wasNullback to summary
public static final Boolean wasNull(CallableStatement statement, Boolean value) throws SQLException

Convenient way to check if a JDBC-originated record was null.

This is useful to check if primitive types obtained from the JDBC API were actually SQL NULL values.

Parameters
statement:CallableStatement

The data source from which a value was read

value:Boolean

The value that was read

Returns:Boolean

The value or null if the CallableStatement#wasNull() is true