How to log sql statement only in case of exception?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How to log sql statement only in case of exception?

Pablo León
Hi,

I don't want to log every sql statement, just the failed ones. How can this be achieved with MyBatis?

Regards,

     Pablo.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to log sql statement only in case of exception?

Jose María Zaragoza
El sáb., 29 sept. 2018 a las 0:20, Pablo León
(<[hidden email]>) escribió:
>
> Hi,
>
> I don't want to log every sql statement, just the failed ones. How can this be achieved with MyBatis?

Maybe by using an interceptor



>
> Regards,
>
>      Pablo.
>
> --
> You received this message because you are subscribed to the Google Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to log sql statement only in case of exception?

Pablo León
I guess that it could be done by surrounding Invocation.proceed() with a try...catch block. Several questions arise:

    1.- How can I get the SQL statement (and params) corresponding to the intercept(invocation) method call?

    2.- Are all exceptions (such as TooManyResultsException) thrown by Invocation.proceed() or are some exceptions thrown by Mybatis in later steps?

Regards.

El sábado, 29 de septiembre de 2018, 9:09:16 (UTC+2), Jose María Zaragoza escribió:
El sáb., 29 sept. 2018 a las 0:20, Pablo León
(<<a href="javascript:" target="_blank" gdf-obfuscated-mailto="9NvMx-WPAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">pablo....@...>) escribió:
>
> Hi,
>
> I don't want to log every sql statement, just the failed ones. How can this be achieved with MyBatis?

Maybe by using an interceptor



>
> Regards,
>
>      Pablo.
>
> --
> You received this message because you are subscribed to the Google Groups "mybatis-user" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="9NvMx-WPAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">mybatis-user...@googlegroups.com.
> For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.