How to associate a Java source file with a database?

Answered

Using IntelliJ 14.0 or 14.1 EAP, I cannot figure out how to change the association of a java file with a database.

I have different databases in my Database tool window. Each of those databases correspond to different versions of my software.
I have java code that contains SQL statements (pure JDBC, prepareStatement, ...).
If I Ctrl+Click a table name in one of those statements for example it always brings me to the same database in the Database tool window.

I am pretty sure that at some point IntelliJ asked me to associate that code with one of my databases but I cannot find how to change that association.
I have searched the Settings, all I can find is how to change the SQL dialect but not the database.

5 comments
Comment actions Permalink

I have the same problem with 2017.3.  The sql fragments in strings in my code shows errors for column names due to the wrong database data source (or possibly no data source at all) being used even though I have the correct database data source in intelliJ. 

It would be very nice if intelliJ checked these fragments for errors, code completed as I write new SQL, and allow me to run these fragments directly from the java source file.

0
Comment actions Permalink

That did it Yaroslav thank you!

It would have been nice to have a context help of some sort.  Finding this in the settings (I did try) was not obvious to me.  Maybe a right click or a "light-bulb" style indicator inline with the sql strings that where showing red underline errors due to the wrong datasource being the default would have been VERY helpful in this case.

Thanks again, thanks for the great product!

Peter

0
Comment actions Permalink

Peter,

There should be "Go to SQL Resolution Scopes" action on "Alt+Enter

 


"

 

0
Comment actions Permalink

Ahhh! Even better thank you. It most likely wasn’t obvious to me what a “sql resolution scope” is so I must have not even tried that one. Now it’s obvious though.

Thanks again!

Peter

0

Please sign in to leave a comment.