|
|
|
|
|
|
|
|
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #491497 is a reply to message #489429] |
Wed, 14 October 2009 15:35  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
Ok... First, the DDL question... The only example I can find is this:
private void executeDDL(String[] sqlStatements,
IConnectionProfile connectionProfile) {
DatabaseIdentifier databaseIdentifier = new DatabaseIdentifier(
connectionProfile.getName(), "");
if (databaseIdentifier != null) {
try {
Job job = new GroupSQLResultRunnable(null, sqlStatements, null,
null, databaseIdentifier, false, new HashMap(),
Messages.BaseExecuteAction_group_exec_title,
"Generate DDL");
job.setName(Messages.BaseExecuteAction_job_title);
job.setUser(true);
job.schedule();
PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage().showView(EditorConstants.RESULTS_VIEW);
} catch (Exception e) {
}
}
}
For the ability to pop up the property page as we do, check out
ConnectAction in o.e.d.connectivity.ui in the
o.e.d.connectivity.ui.actions package. The public void run(IAction
action) method pops up the dialog.
--Fitz
Joshua Hui wrote:
> Hi Fitz,
>
> It will be the latter one which is to execute the DDL file using the
> IConnectionProfile.
>
> Also, if not all the properties are specified (i.e.
> arePropertiesComplete() is false), can I bring up the same properties
> dialog to allow user to enter the valid connection information? If so,
> which command should I use?
>
> Thanks for your help!
>
> Joshua
>
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596499 is a reply to message #488939] |
Wed, 30 September 2009 16:00  |
Joshua Hui Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Hi Fitz,
Instead of directly using java.sql to establish a JDBC connection and manipulate the tables in the database, I would like to leverage DTP to use existing connection profile that is configured in the project and issue SQL statement. It is like the latter answer in your question.
Thanks.
Joshua
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596506 is a reply to message #596499] |
Wed, 30 September 2009 18:49  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
I'll work up an example over the next couple of days. Sorry for the delay.
--Fitz
Joshua Hui wrote:
> Hi Fitz,
>
> Instead of directly using java.sql to establish a JDBC connection and
> manipulate the tables in the database, I would like to leverage DTP to
> use existing connection profile that is configured in the project and
> issue SQL statement. It is like the latter answer in your question.
>
> Thanks.
>
> Joshua
>
>
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596513 is a reply to message #488967] |
Thu, 01 October 2009 12:31  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
Ok...
So to get a named connection profile and connect via APIs, you use:
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();
}
}
And then once you have your IConnectionProfile reference, you can get
the JDBC connection this way:
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;
}
From there you can treat it like any other JDBC connection and create a
JDBC statement and execute it how you'd like.
Does that help?
--Fitz
Brian Fitzpatrick wrote:
> I'll work up an example over the next couple of days. Sorry for the delay.
>
> --Fitz
>
> Joshua Hui wrote:
>> Hi Fitz,
>>
>> Instead of directly using java.sql to establish a JDBC connection and
>> manipulate the tables in the database, I would like to leverage DTP to
>> use existing connection profile that is configured in the project and
>> issue SQL statement. It is like the latter answer in your question.
>>
>> Thanks.
>>
>> Joshua
>>
>>
|
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596533 is a reply to message #489169] |
Thu, 01 October 2009 13:00  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
There really isn't, or wasn't until I created one this morning for FAQs.
You can see it here: http://wiki.eclipse.org/DTP_FAQ
What exactly are you looking for? I have a number of things I'll add to
that page over time.
--Fitz
Joshua Hui wrote:
> Hi Fitz,
>
> Thanks. It is really useful. Really appreciate that.
>
> BTW, apart from javadoc, is there any external document/web site which
> describes how to use the APIs? In that case, if I have any further
> question, I can refer to that.
>
> Joshua
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596540 is a reply to message #489173] |
Thu, 01 October 2009 17:54  |
Joshua Hui Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Hi Fitz,
Apart from using the raw JDBC connection, I am also looking for ways to programmatically invoke a ddl script from DTP. Is there a way to do it?
BTW, I tried your suggestion. It works except for
public java.sql.Connection getJavaConnectionForProfile( IConnectionProfile profile)
I have to change the following to get hold of the sql connection.
IManagedConnection connection = profile.getManagedConnection("java.sql.Connection");
if (connection != null) {
return (java.sql.Connection) connection.getConnection().getRawConnection();
}
return null;
Thanks.
Joshua
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596549 is a reply to message #489216] |
Fri, 02 October 2009 10:49  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
Hi Joshua...
Thanks for the correction - I'll update that code in the FAQ too. :)
Let me ask around and see if we have an example of how to use the APIs
to invoke some DDL.
--Fitz
Joshua Hui wrote:
> Hi Fitz,
>
> Apart from using the raw JDBC connection, I am also looking for ways to
> programmatically invoke a ddl script from DTP. Is there a way to do it?
>
> BTW, I tried your suggestion. It works except for public
> java.sql.Connection getJavaConnectionForProfile(
> IConnectionProfile profile)
>
> I have to change the following to get hold of the sql connection.
>
> IManagedConnection connection =
> profile.getManagedConnection("java.sql.Connection");
>
> if (connection != null) {
> return (java.sql.Connection)
> connection.getConnection().getRawConnection();
> }
> return null;
>
> Thanks.
>
> Joshua
|
|
|
| Re: Programmatically access a JDBC connection via DTP [message #596558 is a reply to message #489352] |
Fri, 02 October 2009 18:33  |
Brian Fitzpatrick Messages: 495 Registered: July 2009 |
Senior Member |
|
|
Hey Joshua...
Are you trying to execute DDL so that the results appear in the results
view or simply execute some DDL with the JDBC connection you got from a
connection profile?
--Fitz
Brian Fitzpatrick wrote:
> Hi Joshua...
>
> Thanks for the correction - I'll update that code in the FAQ too. :)
>
> Let me ask around and see if we have an example of how to use the APIs
> to invoke some DDL.
>
> --Fitz
>
> Joshua Hui wrote:
>> Hi Fitz,
>>
>> Apart from using the raw JDBC connection, I am also looking for ways
>> to programmatically invoke a ddl script from DTP. Is there a way to
>> do it?
>> ...
>> Thanks.
>>
>> Joshua
|
|
|
Powered by
FUDForum. Page generated in 0.02334 seconds