Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DTP » Access Profile Manager @Runtime(ProfileManager.getInstance().getProfileByName @Runtime)
Access Profile Manager @Runtime [message #895216] Thu, 12 July 2012 07:44
Sudesh Bulathsinhala is currently offline Sudesh Bulathsinhala
Messages: 180
Registered: October 2010
Senior Member
Hello,

We have a plugin that consumes the available connection called postgres.sql from Data Source Explorer.
The connection is established and the database-schemas are available in the explorer during @design-time in IDE.

I followed the instructions given in http://wiki.eclipse.org/DTP_FAQ

IConnectionProfile postgresProfile = ProfileManager.getInstance().getProfileByName("postgres.sql");
  IStatus status = profile.connect();
  if (status.getCode() == IStatus.OK)) {
     // success
  } else {
     // failure :(
     if (status.getException() != null) {
        status.getException().printStackTrace();
     }
  } 

public java.sql.Connection getJavaConnectionForProfile (IConnectionProfile profile) {
     IManagedConnection managedConnection = ((IConnectionProfile)profile).
        getManagedConnection ("java.sql.Connection");
     if (managedConnection != null) {
        return (java.sql.Connection) managedConnection.getConnection().getRawConnection();
     }
     return null;
  }

java.sql.Connection conn = getJavaConnectionForProfile(postgresProfile);
  if (conn != null) {
     try {
        java.sql.Statement stmt = conn.createStatement();
        java.sql.ResultSet results = stmt.executeQuery("<INSERT QUERY/DDL HERE>");
     } catch (java.sql.SQLException sqle) {
        sqle.printStackTrace();
     }
  }



However, once we invoke RCP application with this plugin, it always throw NPE, while executing the above code.

I debug and found the following returns an empty array during @runtime.
IConnectionProfile[] profiles = ProfileManager.getInstance().getProfiles();



Am I missing something here ?

Thanks & Regards,
Sudesh Bulathsinhala
Previous Topic:Connecting to MS Database 2008
Next Topic:input ddl without ui
Goto Forum:
  


Current Time: Sat Oct 25 10:15:28 GMT 2014

Powered by FUDForum. Page generated in 0.07453 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software