How can I print JDBC driver logs to the Services panel's output?

Answered

I have developed a JDBC driver to read a data stream and present the data in a table like querying MySQL. 

When querying the data stream in the driver, there are some log outputs to facilitate understanding the progress of the query. I want to print these log outputs to the output. Can someone please tell me how to do this? Thank you very much.

0
7 comments
Official comment

Hi cpwm,

You can independently retrieve your JDBC output on-the-fly during query execution and display it in the Output. 
To output, you need to use com.intellij.database.datagrid.DataRequest.Context with your query. 
It has methods like print, warn, error that you can use to write something to the Output (please, for your purpose, use the method warn).

To get com.intellij.database.datagrid.DataRequest.Context, you can add your com.intellij.database.datagrid.DataAuditor:

val listener = MyDataAuditor()
Disposer.register(console, listener)
console.messageBus.addAuditor(listener)

The only way you can accomplish that is to implement getAllWarnings() methods for result set or statements and return your messages in them
 

0

Thank you very much

0

There is a problem with using the getAllWarnings() method to print logs is that logs cannot be printed in real time and will be printed after the sql execution is complete.
If I print sql execution log in DatabaseConnectionInterceptor implementation class ,  Is there any way to do that?
Thank you very much.

0

Anna Rodionova  Thank you for your reply, I wanted to make a try, but reported an error, I tried to solve, did not find the answer. I really can't find this class in the sdk.

0

The class not found issue,  not found 

The problem with the class(com.intellij.database.datagrid.GridDataRequest) not being found has been solved by adding the "intellij.grid.core.impl" dependency in the build.gradle.kts file。

0

Please sign in to leave a comment.