Module org.jooq

Class JDBCUtils


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

      • driver

        public static final 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​(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