Class OracleDBMSOutputListener

  • All Implemented Interfaces:
    AutoCloseable

    public class OracleDBMSOutputListener
    extends Object
    implements AutoCloseable
    A utility to read DBMS output from an Oracle database.

    This allows your stored procedures to emit logging output that can be consumed by other parts of your codebase.

    Since DBMS_OUTPUT is specific to a session, output will be read in a separate thread from your main process, so your JDBC driver must be thread-safe.

    Usage of this class looks like this:

    Open a connection to the target DB Create new OracleDBMSOutputListener, registering your callback Invoke begin() Construct and invoke your other stored procedure(s) -> Your callback will receive asynchronous lines of DBMS_OUTPUT Close the OracleDBMSOutputListener Close the connection to the target DB

    When you’re done reading output, invoke close() on this class to clean up resources. Failure to do this will result in prepared statement resource leaks.

    • Method Detail

      • close

        public void close()
                   throws Exception
        Closes this listener by cleaning up the various worker and JDBC objects.

        The worker will be interrupted and its getLineStatement closed if present. The DBMS_OUTPUT will be toggled off for the current connection.

        Specified by:
        close in interface AutoCloseable
        Throws:
        Exception - if there are any errors closing the connections
      • listen

        public void listen()
                    throws SQLException
        Enables DBMS_OUTPUT and starts up the background listener.

        This should be invoked before your stored procedure is called.

        Throws:
        SQLException - if there is a problem starting DBMS_OUTPUT