Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » DTP » How to create a database object by code
How to create a database object by code [message #641953] Mon, 29 November 2010 11:07 Go to next message
Henzler Peter is currently offline Henzler PeterFriend
Messages: 19
Registered: July 2009
Junior Member
Hi

I would like to use the datatools plugins to validate a DB2 SQL query against a DB2 database.

I found this description:
http://www.eclipse.org/datatools/project_sqldevtools/sqltool s_doc/SQL%20Query%20Parser%20User%20documentation.htm

But I cant find out how to get the Database object for the desired DB2 database to validate the tables and fields like described under 2.3

The code below is not working, because
managedConnection.getConnection().getRawConnection()
can not be cast to ConnectionInfo.

Can anyone help?






Properties baseProperties = new Properties();
baseProperties
.setProperty(
IDriverMgmtConstants.PROP_DEFN_JARLIST,
"C:\\Program Files\\IBM\\IBM Data Studio stand-alone\\plugins\\com.ibm.datatools.db2_2.1.102.v2009102 4_0211\\driver\\db2jcc.jar ");
baseProperties.setProperty(IJDBCDriverDefinitionConstants.DA TABASE_CATEGORY_ID,
ILUWConnectionProfileConstants.DB2_LUW_CATEGORY_ID);
baseProperties.setProperty(IJDBCConnectionProfileConstants.D ATABASE_NAME_PROP_ID, "SCODIREP");
baseProperties.setProperty(IJDBCConnectionProfileConstants.D RIVER_CLASS_PROP_ID, "com.ibm.db2.jcc.DB2Driver");
baseProperties.setProperty(IJDBCConnectionProfileConstants.U RL_PROP_ID, "jdbc:db2://localhost:50000/SCODIREP");
baseProperties.setProperty(IJDBCConnectionProfileConstants.U SERNAME_PROP_ID, user);
baseProperties.setProperty(IJDBCConnectionProfileConstants.P ASSWORD_PROP_ID, password);
baseProperties.setProperty(IJDBCConnectionProfileConstants.D ATABASE_VENDOR_PROP_ID, "DB2 UDB");
baseProperties.setProperty(IJDBCConnectionProfileConstants.D ATABASE_VERSION_PROP_ID, "V9.1");
// baseProperties.setProperty( IJDBCConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, String.valueOf( true ) );

IConnectionProfile profile = null;
try {
profile = ProfileManager.getInstance().createTransientProfile(
" org.eclipse.datatools.enablement.ibm.db2.luw.connectionProfi le ", baseProperties);
} catch (ConnectionProfileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

org.eclipse.datatools.enablement.ibm.db2.internal.luw.JDBCLU WConnectionFactory fac = new JDBCLUWConnectionFactory();
IConnection iConnection = fac.createConnection(profile, user, password);

Database db = null;
IManagedConnection managedConnection = iConnection.getConnectionProfile().getManagedConnection(
" org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");
if (managedConnection != null) {
try {
ConnectionInfo connectionInfo = (ConnectionInfo) managedConnection.getConnection().getRawConnection();
if (connectionInfo != null) {
db = connectionInfo.getSharedDatabase();
}
} catch (Exception e) {
e.printStackTrace();
throw new ValidationException("db", e);
}
}

Re: How to create a database object by code [message #642552 is a reply to message #641953] Wed, 01 December 2010 18:37 Go to previous message
Brian Fitzpatrick is currently offline Brian FitzpatrickFriend
Messages: 500
Registered: July 2009
Senior Member
Hi there...

There's some details here: http://wiki.eclipse.org/DTP_FAQ that should
help you create a transient connection profile and then get the database
model for the connection profile... See specifically "Q: How do I get at
the database model from my connected connection profile?" and "Q: How do
I create a Transient connection profile vs. a Persisted profile?"

Hope that helps!
--Fitz

Henzler Peter wrote:
> Hi
>
> I would like to use the datatools plugins to validate a DB2 SQL query
> against a DB2 database.
>
> I found this description:
> http://www.eclipse.org/datatools/project_sqldevtools/sqltool s_doc/SQL%20Query%20Parser%20User%20documentation.htm
>
> But I cant find out how to get the Database object for the desired DB2
> database to validate the tables and fields like described under 2.3
>
> The code below is not working, because
> managedConnection.getConnection().getRawConnection()
> can not be cast to ConnectionInfo.
>
> Can anyone help?
>
>
>
>
>
>
> Properties baseProperties = new Properties();
> baseProperties
> .setProperty(
> IDriverMgmtConstants.PROP_DEFN_JARLIST,
> "C:\\Program Files\\IBM\\IBM Data
> Studio stand-alone\\plugins\\com.ibm.datatools.db2_2.1.102.v2009102
> 4_0211\\driver\\db2jcc.jar ");
>
> baseProperties.setProperty(IJDBCDriverDefinitionConstants.DA
> TABASE_CATEGORY_ID,
>
> ILUWConnectionProfileConstants.DB2_LUW_CATEGORY_ID);
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.D
> ATABASE_NAME_PROP_ID, "SCODIREP");
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.D
> RIVER_CLASS_PROP_ID, "com.ibm.db2.jcc.DB2Driver");
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.U RL_PROP_ID,
> "jdbc:db2://localhost:50000/SCODIREP");
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.U
> SERNAME_PROP_ID, user);
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.P
> ASSWORD_PROP_ID, password);
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.D
> ATABASE_VENDOR_PROP_ID, "DB2 UDB");
>
> baseProperties.setProperty(IJDBCConnectionProfileConstants.D
> ATABASE_VERSION_PROP_ID, "V9.1");
> // baseProperties.setProperty(
> IJDBCConnectionProfileConstants.SAVE_PASSWORD_PROP_ID, String.valueOf(
> true ) );
>
> IConnectionProfile profile = null;
> try {
> profile =
> ProfileManager.getInstance().createTransientProfile(
> "
> org.eclipse.datatools.enablement.ibm.db2.luw.connectionProfi le ",
> baseProperties);
> } catch (ConnectionProfileException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
>
> org.eclipse.datatools.enablement.ibm.db2.internal.luw.JDBCLU
> WConnectionFactory fac = new JDBCLUWConnectionFactory();
> IConnection iConnection = fac.createConnection(profile,
> user, password);
>
> Database db = null;
> IManagedConnection managedConnection =
> iConnection.getConnectionProfile().getManagedConnection(
> "
> org.eclipse.datatools.connectivity.sqm.core.connection.Conne ctionInfo ");
> if (managedConnection != null) {
> try {
> ConnectionInfo connectionInfo = (ConnectionInfo)
> managedConnection.getConnection().getRawConnection();
> if (connectionInfo != null) {
> db = connectionInfo.getSharedDatabase();
> }
> } catch (Exception e) {
> e.printStackTrace();
> throw new ValidationException("db", e);
> }
> }
>
>
Previous Topic:Semicolon problem on multiple inserts
Next Topic:It takes too much time to open DTP perspective.
Goto Forum:
  


Current Time: Wed Apr 24 21:26:19 GMT 2024

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

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

Back to the top