Jump to: navigation, search

Difference between revisions of "DTP FAQ"

(New page: {{Back To|name=DTP Main Page|href=Data Tools Platform Project}} = DTP Frequently Asked Questions (FAQ) = == Connectivity == Q: How do I programmatically access an existing connection p...)
 
Line 5: Line 5:
 
== Connectivity ==
 
== Connectivity ==
  
Q: How do I programmatically access an existing connection profile?
+
'''Q: How do I programmatically access an existing connection profile?'''
  
 
A: This is pretty simple:
 
A: This is pretty simple:
  
IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("myprofile");
+
  IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("myprofile");
  
Q: How do I connect to an existing connection profile programmatically?
+
'''Q: How do I connect to an existing connection profile programmatically?'''
  
 
A: Again, pretty simple:
 
A: Again, pretty simple:
  
IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("myprofile");
+
  IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("myprofile");
IStatus status = profile.connect();
+
  IStatus status = profile.connect();
if (status.equals(IStatus.OK)) {
+
  if (status.equals(IStatus.OK)) {
  // success
+
      // success
} else {
+
  } else {
  // failure :(
+
      // failure :(
  if (status.getException() != null) {
+
      if (status.getException() != null) {
      status.getException().printStackTrace();
+
        status.getException().printStackTrace();
  }
+
      }
}  
+
  }  
  
Q: How do I get the raw JDBC Connection from my connected connection profile?
+
'''Q: How do I get the raw JDBC Connection from my connected connection profile?'''
  
public java.sql.Connection getJavaConnectionForProfile (IConnectionProfile profile) {
+
  public java.sql.Connection getJavaConnectionForProfile (IConnectionProfile profile) {
  IConnection connection = ProfileConnectionManager.getProfileConnectionManagerInstance().getConnection(profile,"java.sql.Connection");
+
      IConnection connection = ProfileConnectionManager.getProfileConnectionManagerInstance().getConnection(profile,"java.sql.Connection");
  if (connection != null) {
+
      if (connection != null) {
      return (java.sql.Connection) connection.getRawConnection();
+
        return (java.sql.Connection) connection.getRawConnection();
  }
+
      }
  return null;
+
      return null;
}  
+
  }  
  
 
[[Category:Data_Tools_Platform]]
 
[[Category:Data_Tools_Platform]]

Revision as of 12:44, 1 October 2009

Back to DTP Main Page


DTP Frequently Asked Questions (FAQ)

Connectivity

Q: How do I programmatically access an existing connection profile?

A: This is pretty simple:

  IConnectionProfile profile = ProfileManager.getInstance().getProfileByName("myprofile");

Q: How do I connect to an existing connection profile programmatically?

A: Again, pretty simple:

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

Q: How do I get the raw JDBC Connection from my connected connection profile?

  public java.sql.Connection getJavaConnectionForProfile (IConnectionProfile profile) {
     IConnection connection = ProfileConnectionManager.getProfileConnectionManagerInstance().getConnection(profile,"java.sql.Connection");
     if (connection != null) {
        return (java.sql.Connection) connection.getRawConnection();
     }
     return null;
  }