How to execute the sql with the native database api

Answered

I want to execute the sql,but now I can only generate a temp file and open it with the fileeditor.I don't know how to run it with the native database api?the datasource have been got.

0
11 comments

What are your use scenarios, maybe JDBC?

0

I wrote a plugin for mybatis.And I have opened the fileeditor with the sql,but I have no idea about auto execute it.

0

I think you can look at the manual execution button, see how does its Action source code execute

0

Karol Lewandowski I want to execute the sql in the sql fileeditor,just like auto click the run button.

0

What do you mean by auto click? Is there any existing similar feature? If yes, please show what you mean on a screenshot.

0

@Karol Lewandowski my plugin has implements to open the fileeditor by generated sql file.

but I have no idea to execute it.I want to make it execute like the database tool.

0

I'm not familiar with Database Tools and don't understand what feature you mean. Please refer to the existing feature.

0

Karol Lewandowski You mean I can only process the execution by myself?I have tried with this

but the console does't print the log.when I debug the system.out.println,I found it not work.

0

I have used the api,but can not execute with the nullpointerexception

0

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 override processRaw 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) .
 

0

Please sign in to leave a comment.