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