Community
Participate
Working Groups
The data tools currently allow a user to work with databases but do not help Java developers integrate DB connections in their code. I'd like to see an option (possibly on the context menu) that allows users to insert JDBC connections into their Java code for databases which have already been defined. Taking this further, it would also be useful to insert a statement that allows a user to get the values from an SQL statement. This should probably be linked with the SQL editor.
Great idea, but this enhancement request does not fit into the scope of WTP project.
Agreed. I'm retargetting to DTP.
I opened this bug against WTP but with the formation of the DTP project I'm reassigning to DTP.
Actually, I had a discussion with John D at EclipseCon about this sort of thing. Interested in how we would integrate with the Java editor: use a code template or something like that?
Hey John, I'm afraid we won't be able to do this in 1.0.
Do you guys (DTP guys) have any pointers you can give here on where to retrieve the DB connection info from (API would be nice) so as to help anyone who wants to work on this enhancement? I think a code snippet or content assist may be the way to go to integrate this in the Java editor. Thanks.
I think you should check out org.eclipse.datatools.connectivity.ProfileManager, which defines API such as: getProfiles, getProfilesByCategory, etc.
Has anyone worked on this? If not, I'd like to contribute this enhancement. I had a prototype on the hand already, and just need a little bit refine for several days. Let me know.
(In reply to comment #8) Hi, There is no active work done for this thus far. Can you please post more description regarding the prototype that you have; how it works, etc.? And what sort of info that you might need? Thanks for your contribution. Linda
(In reply to comment #9) I'm using the javaCompletionProposalComputer extension point for hooking the proposal into JDT. If user input the data source name and press ctrl-space in Java Editor, it'll get the matched data source lists. User the data source will generating the JDBC connection string in the code. See the attached pic. My questions are: 1. The jdbc string is vendor dependent (am i right?). If yes, I need get this form the profile (or?). Does DTP have this already? Or guessing at the UI side? 2. I'm using a separate project at the moment. Where to put the code? Cheers Qiangsheng
Created attachment 160013 [details] screen shot
Created attachment 160014 [details] screen shot
It's nice to see some traction on this old request. Thanks for stepping up Qiangsheng.
I attached the completed code as a separate project. I'm using the IJDBCConnectionProfileConstants.URL_PROP_ID property to retrieve the URL. I'm not an expert of DTP, so if this is not correct then please let me know.
Created attachment 160886 [details] The project for the jdbc compeletion.
Hi there... Just one comment about the attached project. One of the package names is incorrect, so you end up with "org.eclipse.datatools.sqltools.internal.*" and "org.eclipse.datatools.sqltools.inertnal.*". Beyond that, can you provide a series of steps to try out the code?
Yes, apparently my figure was out of control when typing "internal". Attached the new project. Well in term of using it, I assume you're using the source project. 1. Import the attached project. 2. Run a new run-time configuration. Make sure you include the new plugin. 3. Create one/several data base connections via DTP data source explorer view. 4. Create a java project, create java files in it. 5. Open a java file, typing the begging letters of a data source name. 6. Press ctrl-space. You should get the matching data base names in the list 7. Select on of the data base name, you'll get the URL connection string. You can see my previous screen shot.
Created attachment 161044 [details] New project with correct package name.
BTW the connections.txt file in the project is a temp file. We don't really need it.
Hey Lawrence... Are you already a committer at Eclipse? I think we should be able to work this functionality into DTP for the 1.9 release (with Eclipse Indigo). But we'll have to go through an IP review because of the size of the contribution. It's not huge, but is still going to take some time.
Hi Brian. I'm a former WTP committer. As you can see from the bug history, this request is 5 years old. I'm not currently in a position to help integrate the contribution but I would be happy to test it once it's included in a build.
Hi Lawrence - that's awesome. Testing help is always appreciated. :) The contribution is small (less than 11k of code) - I just want to make sure that IP-wise we're ok to include it in our Indigo release. I think this contribution would be a good start at least. Right now if you use it and type the name of a connection profile (without spaces), you will see a list of profiles (if you have more than one) - select one and it will insert the JDBC URL into the text. We could do other things such as adding your typical code block: // From connection profile: NewSQLite Class.forName("org.sqlite.JDBC"); Connection conn = DriverManager.getConnection("jdbc:sqlite:/home/bfitzpat/DBs/MySQLiteDB"); Which I think is more in the spirit of your original request.
The new suggested code looks better than mine. :)