How to execute sql with database tool's sqleditor
已回答
I have wrote a plugin about mybatis.And now I want to add some feature to execute the mybatis sql log.But I don't know how to open the sqleditor with the sql and automatically execute the sql and show the result in the console.please tell me how to make it with the database tool api.
请先登录再写评论。
Hi!
To execute the SQL, you need to:
1. Create or get existing session by using
com.intellij.database.console.session.DatabaseSessionManager#getSessions(com.intellij.openapi.project.Project, com.intellij.database.dataSource.LocalDataSource)
.2. Create request
com.intellij.database.datagrid.DataRequest.RawRequest
and overrideprocessRaw
method. Here you can get the connection from the second argument -com.intellij.database.dataSource.DatabaseConnectionCore#getRemoteConnection
.3. Send the request for execution
session.getMessageBus().getDataProducer().processRequest(request)
.