DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Daniel have developed support for proprietary technology which is processing huge volumes of XML data. Now is working on Register of traffic accidents(J2EE application build on Websphere) for Ministry of Interior of the Slovak Republic. Daniel has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

Idea plugin - using DataSource

05.29.2013
| 3628 views |
  • submit to reddit
import com.intellij.javaee.dataSource.DataSource;
import com.intellij.javaee.dataSource.DataSourceManager;
import com.intellij.javaee.dataSource.ServerInstance;
import com.intellij.openapi.project.Project;
import java.lang.reflect.Method;
import java.sql.Connection;
...

DataSourceManager dataSourceManager = 
DataSourceManager.getInstance(e.getProject());
DataSource dataSource = 
dataSourceManager.getDataSourceByName("BB21_TST"); 
Method getConnectionMethod  = 
dataSource.getClass().getDeclaredMethod("getConnection", Project.class, ServerInstance.class);
getConnectionMethod.setAccessible(true);
Connection conn =
 (Connection) getConnectionMethod.invoke(dataSource, p, null);

Because i haven't found better solution, if there is any pls help me out. No one helped this poor guy:

http://devnet.jetbrains.com/message/5202001#5202001

So I guess there is non. 

And for the guys from JetBrains, it's easy to use connection from data source when making plugin for NetBeans IDE.