Module org.jooq

Class JDBCUtils

java.lang.Object
org.jooq.tools.jdbc.JDBCUtils

public class JDBCUtils extends Object
JDBC-related utility methods.
Author:
Lukas Eder
  • Method Details

    • dialect

      @NotNull 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:
      The appropriate SQLDialect or SQLDialect.DEFAULT if no dialect could be derived from the connection. Never null.
      See Also:
    • dialect

      @NotNull public static final @NotNull SQLDialect dialect(io.r2dbc.spi.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:
      The appropriate SQLDialect or SQLDialect.DEFAULT if no dialect could be derived from the connection. Never null.
      See Also:
    • dialect

      @NotNull public static final @NotNull SQLDialect dialect(io.r2dbc.spi.Connection connection)
      "Guess" the SQLDialect from an R2DBC Connection instance.

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

      Returns:
      The appropriate SQLDialect or SQLDialect.DEFAULT if no dialect could be derived from the connection. Never null.
      See Also:
    • dialect

      @NotNull public static final @NotNull SQLDialect dialect(String url)
      "Guess" the SQLDialect from a connection URL.
      Returns:
      The appropriate SQLDialect or SQLDialect.DEFAULT if no dialect could be derived from the connection. Never null.
    • driver

      @NotNull public static final @NotNull String driver(SQLDialect dialect)
      "Guess" the JDBC driver from a SQLDialect.
      Returns:
      The appropriate JDBC driver class or "java.sql.Driver" if no driver class could be derived from the URL. Never null.
    • 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. Never null.
    • safeClose

      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.

    • safeClose

      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.

    • safeClose

      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.

    • 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 resultSet or statement is null, or if ResultSet.close() or Statement.close() throws an exception.

    • safeClose

      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.

    • safeClose

      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.

    • safeFree

      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.

    • safeFree

      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.

    • safeFree

      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.

    • safeFree

      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.

    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the SQLInput.wasNull() is true
      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 was null.

      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 read
      value - The value that was read
      Returns:
      The value or null if the SQLInput.wasNull() is true
      Throws:
      SQLException
    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the SQLInput.wasNull() is true
      Throws:
      SQLException
    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the ResultSet.wasNull() is true
      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 was null.

      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 read
      value - The value that was read
      Returns:
      The value or null if the ResultSet.wasNull() is true
      Throws:
      SQLException
    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the ResultSet.wasNull() is true
      Throws:
      SQLException
    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the CallableStatement.wasNull() is true
      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 was null.

      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 read
      value - The value that was read
      Returns:
      The value or null if the CallableStatement.wasNull() is true
      Throws:
      SQLException
    • wasNull

      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 - The data source from which a value was read
      value - The value that was read
      Returns:
      The value or null if the CallableStatement.wasNull() is true
      Throws:
      SQLException