Can I create DB connection manually from plugin?

Hello.

I want to automatically creating DB connection from my plugin, but cannot find some documentation how can I do that for official DB management plugin in IDEA Ultimate.

I've investigate some code and find jar of plugin in <user_idea_dir>/config/plugins/DBNavigator/dbn.jar

1) Include dbn.jar to project as provided library

2) Add to plugins.xml dependency and action:

<depends>com.intellij.modules.database</depends>
<actions>
<!-- Add your actions here -->
<group id="SpconfigPlugin.SampleMenu" text="_Sample Menu" description="Sample menu">
<add-to-group group-id="MainMenu" anchor="last"/>
<action id="SpconfigPlugin.Menu" class="Menu" text="SPConfig" description="Spconfig!!!">
</action>
</group>

</actions>

3) In Action wrote something like this (just for example, that code should open window that allow to configure new PostgreSQL connection

import com.dci.intellij.dbn.connection.DatabaseType;
import com.dci.intellij.dbn.connection.config.ConnectionConfigType;
import com.dci.intellij.dbn.options.ProjectSettingsManager;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.Project;

/**
* Created by mds on 29.03.17.
*/
public class Menu extends AnAction {

@Override
public void actionPerformed(AnActionEvent event) {
Project project = event.getData(PlatformDataKeys.PROJECT);
if (project != null) {
ProjectSettingsManager settingsManager = ProjectSettingsManager.getInstance(project);
ConnectionConfigType configType = ConnectionConfigType.BASIC;

settingsManager.createConnection(DatabaseType.POSTGRES, configType);
}
}
}

 

After compile and running I've got an Exceptions - ClassDefNotFound for com.dci.* packages.

In final solution I just want add new Postgres connection to DB list with specified parameters.

1 comment
Comment actions Permalink

Sorry, wrong plugin, what I need in <idea_ultimate>/plugins/DatabaseTools

 

0

Please sign in to leave a comment.