Last Updated on 30 November 2020   |   Print Email
IntelliJ IDEA comes with a very cool feature that provides auto completion and inspection for writing SQL statements write inside Java code such as SQL syntax suggestion; table and column names suggestion for the configured datasources in the project.If somehow the SQL autocomplete feature is not working in IntelliJ IDEA, you can follow the following two steps to fix it.
1. Set language reference as SQL
If IntelliJ doesn’t recognize the SQL literal (with SQL keywords are in orange color), place the caret inside the SQL literal and press Alt + Enter to show the available hints:Then choose Inject language or reference, and select SQL from the list of languages:The you will see IntelliJ recognizes the String literal as SQL statement, as shown below:
Now, if you press Ctrl + Space, you will see the autocomplete for SQL keywords – not for names of tables and columns in the configured data sources. So perform the last step below.
2. Set SQL Dialect
Press Shift two times (double Shift) to see the quick search dialog, and type SQL dialects:Wait a couple of seconds to see the SQL Dialects Settings and click it. Then in the Settings dialog, choose the appropriate SQL dialect, e.g. MySQL:Click OK, and come back to edit the SQL statement, you should see the auto completion for table names and column names:That’s 2 steps to fix the SQL autocomplete not working issue in IntelliJ IDEA. Enjoy coding!To see the solution in action, watch this video:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.
Comments