Documentation Home
MySQL Connector/J 8.0 Developer Guide
Related Documentation Download this Manual
PDF (US Ltr) - 461.4Kb
PDF (A4) - 463.3Kb
HTML Download (TGZ) - 111.6Kb
HTML Download (Zip) - 129.2Kb


MySQL Connector/J 8.0 Developer Guide  /  Using the Connector/J Interceptor Classes

Chapter 10 Using the Connector/J Interceptor Classes

An interceptor is a software design pattern that provides a transparent way to extend or modify some aspect of a program, similar to a user exit. No recompiling is required. With Connector/J, the interceptors are enabled and disabled by updating the connection string to refer to different sets of interceptor classes that you instantiate.

The connection properties that control the interceptors are explained in Section 6.3, “Configuration Properties”:

  • connectionLifecycleInterceptors, where you specify the fully qualified names of classes that implement the com.mysql.cj.jdbc.interceptors.ConnectionLifecycleInterceptor interface. In these kinds of interceptor classes, you might log events such as rollbacks, measure the time between transaction start and end, or count events such as calls to setAutoCommit().

  • exceptionInterceptors, where you specify the fully qualified names of classes that implement the com.mysql.cj.exceptions.ExceptionInterceptor interface. In these kinds of interceptor classes, you might add extra diagnostic information to exceptions that can have multiple causes or indicate a problem with server settings. exceptionInterceptors classes are called when handling an Exception thrown from Connector/J code.

  • queryInterceptors, where you specify the fully qualified names of classes that implement the com.mysql.cj.interceptors.QueryInterceptor interface. In these kinds of interceptor classes, you might change or augment the processing done by certain kinds of statements, such as automatically checking for queried data in a memcached server, rewriting slow queries, logging information about statement execution, or route requests to remote servers.


User Comments
User comments in this section are, as the name implies, provided by MySQL users. The MySQL documentation team is not responsible for, nor do they endorse, any of the information provided here.
Sign Up Login You must be logged in to post a comment.