Does anyone know how I turn off the SQL validation in Intellij IDEA 9?
We often have more than one connection to a different type of database within one class. IntelliJ only allows one SQL dialect per class, resulting in what IntelliJ thinks are errors, so litters my code with red lines.
Ideally I'd just like to turn the errors off completely, as they are distracting and not actually real errors.
Settings > Inspections. Unselect 'SQL'. Alternatively you can place your cursor on the error and press alt+enter. One of the options will be 'Disable Inspection'.
You could use a comment language= before the statement, i.E.
//language=MySQL
String stmt1 = "INSERT INTO a (b) values(?)";
//language=Oracle
String stmt2 = "SELECT SYSDATE FROM dual";
See https://www.jetbrains.com/idea/help/using-language-injections.html
You can alternatively turn off the specific inspection that is bothering you. No need to turn off all SQL support (e.g. auto-complete hints are nice).
To do this, you can go to Settings --> Editor --> Inspections --> SQL and uncheck the ones you don't want. For instance, I just disabled "No data sources configured" and "Unresolved reference".
In IntelliJ Ultimate 2019.2, this looks like this:
for IntelliJ IDEA 2017.3 you can disable sql inspections:
File | Settings | Inspections | SQL
Usually I just put my cursor to the right of the error so the lightbulb appears. Them press alt-enter and then arrow-right. Another menu pops up that provides various supression options.
I'm not totally sure this will let you supress all the warnings globally, but you usually get rid of the ones that are troubling you fairly quickly.
No longer exists in 2018.2 Community Edition. No SQL under "Inspection" part.
Found a ticket here:
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206751355-Database-navigator-plugin-generates-errors
Seems no solution yet. I am with DB navigator 3.1.
Related
I'm trying to map some Java classes using the Hibernate JPA implementation. My problem is that I can't use hardcoded Strings als column namens. You can see the error message I get in the picture below.
I'm using OpenJPA as my Default JPA Provider and have already tried to change it.
IntelliJ Version 14.0.3
regards,
You have to associate your data source (create a data source in database view first - aka your real JDBC database connection) with a persistence unit or session factory (hibernate.cfg.xml).
Follow below steps and the warnings will disappear:
Open the Persistence tool window (View | Tool Windows |
Persistence).
Right-click the necessary module, persistence unit or
session factory, and select Assign Data Sources in the context menu.
In the Assign Data Sources dialog that opens, click the Data Source
field and select the necessary data source. (To remove the
association with the data source, select none.)
See here: Associating data sources with session factories and persistence units
For those who just want to disable this check, go to
Intellij IDEA -> Preferences -> Search "Unresolved database references in annotations" and uncheck it.
(macOS Mojave and Intellij Ultimate 2019.3)
This will disable the inspection and remove all the "Cannot resolve column…" errors on the #Column annotations. Intellij will stop checking if the String column names exist in the database tables. Do it at your own risk.
I found Panos' answer useful, but I didn't see anybody mention adding the database as a data source. Perhaps that's routine enough to be assumed, but if not, here's what I had to do:
Select View/Tool Windows/Database
The Database window usually appears on the top right.
In the Database window, click the green + sign and select Data Source/MySQL (or whatever flavor of Data Source you're using).
The Data Sources and Drivers window pops up.
If your database isn't listed there, use the empty form to add the following:
Host: usually localhost, but if your test database is living
on another machine, put that address in.
Username: for your database use.
Password: for your database user's password.
IDEA might need some fiddling to find the JDBC driver. I was told that in theory it should have found it in the maven build process for the project I was working on, but it did not. I reopened View/Tool Windows/Database and looked at my MySQL entry. At the bottom it had an error message next to Driver:, and also a MySQL link. I clicked the MySQL link and IDEA brought up a popup to fetch Connector/J.
Despite the fact that the checkboxes for Auto commit and Auto sync defaulted to checked and I left them that way, IDEA seemed to need a nudge. Or perhaps it was just taking a while and I was impatient.
In any event, first I double-clicked on the line for my database in Database. That seemed to do it, but I didn't realize I needed Persistence yet, and while sorting that out, at a coworker's suggestion, I also clicked the Synchronize button (two arrows in a circle) on Database.
You can also right-click on your database in Database and select Synchronize.
It may take a few seconds, but you should see IDEA filling in the database schema under the entry in Database.
Finally I found Panos's answer and fixed Persistence.
Select View/Tool Windows/Persistence
The Persistence window usually appears on the top left.
In the Persistence window, right-click on your project and select Assign Data Sources.
IDEA pops up a dialog with two columns, your project in the left column and in my case an empty cell in the right column. Click on the empty cell and IDEA should give you a dropdown that allows you to select the database you just added.
Again, it may take a few seconds for IDEA to finish analyzing the data source and redo all the inspections.
Just for anyone else whom this didn't solve and comes across via google (like myself) .. setting the table name via the #Table Annotation fixed it for me.
Actually this is not any error that prevents your code to compile. Probably your spell-checker is on and which gives you the spelling mistake. If you can compile your code then you may ignore these type of scenario.
Look you have not getting any error for other text like #Column, #GeneratedValue etc. That means jars using these kind of stuff are in your build path. So I think you can ignore these type of error.
maybe this solution also help someone...
Open Database dialog window from the right side of Intellij
Go to DB Data Source Properties (find it in top menu)
Go to Schemas
Uncheck "Default database"
Check your specific DB and inside also check Default schema(public)
Good luck!
If you are using the JPA, it is also important to set up the SQL Dialect as
HSQLDB instead of MySQL. This is often confusing because it feels like MySQL is the correct dialect, but in fact what you are dealing with hibernate is HSQL.
If you have just upgraded to IntelliJ 2017.13 or other derivatives of this version (e.g., Webstorm), or you've just re-imported your project, it might mess up the language injection and need to manually correct this.
This can be accomplished via the Project
Settings -> Languages and Frameworks
part of the IDE.
If there is no real mismatch and this warning happens just because of IDE, you can easily link your project with the data source that you connect. Intellij already suggests the way to do it.
I'm using Intellij and connecting DB by JPA. I've met problem just like you and this is my solution.
You need to connect your database following these steps:
View -> Tool Windows -> Database -> then add database you are using to Intellj
After connect your database, you need to assign data source to Intellj by following these
View -> Tool Windows -> Persistence -> then add data from database you just added from 1 step
OK. That's all!
P/s: make sure your code work well!
How do I disable code completion but keep suggestions enabled? Every time I type object.Method() without passing any parameters I get something similar to object.Method(datatype). Netbeans would complete the code after the first parenthesis, (. When I don't want to pass any parameters, I simply type ) once. I would get something like this thanks to auto complete: object.Method())
The null in between () would be replaced by the ) I typed.
I want to be able to see suggested code without ctrl-space and without having netbeans automatically insert the code for me. In netbeans I can disable the auto insertion of the second bracket } after I type the first {. I don't have an option to disable parentheses from auto inserting. The problem is that if I disable code completion, I also disable the automatic pop-up that gives me related code. Any advice?
If you do not want the IDE to perform the project updates, you can disable the build analyzer as follows:
Right-click the project node in the Projects window and select Properties.
In the Project Properties dialog box, click the Code Assistance category.
Deselect the Use Build Analyzer option.
https://netbeans.org/kb/docs/cnd/HowTos.html
It's been awhile since I used NetBeans (personally I prefer IntelliJ), but I believe you're using the wrong setting. Try this: under Tools>Options>Editor>General, uncheck "Insert Closing Bracket Automatically".
See also this other question: NetBeans curly braces auto-closing
I have properly configured Datasource in IntelliJ IDEA and I've successfuly tested the connection. I use mysql and I have set all the files to MySQL language.
Now when I try to write SQL simply into a String like this:
connection.prepareStatement("INSERT INTO DeliveryInformation ...");
It won't suggest anything, nor autocomplete ! However when I type
connection.prepareStatement("INSERT INTO 'DeliveryInformation' ...");
then inside those quotes, autocomplete works. But SQL with quotes gives me a syntax error. What am I doing wrong ?
I've figured it out already. SQL code completion started to work after setting injection-language to "keywords" (default) and then to MySQL again.
Try to run the your code. If still there is a error some thing wrong with your code. else hit Alt+Enter and disable Inspection will solve that syntax problem. this is not a actual error.
No need to put single quotation for table name.. that will be the issue.
I'm using the JTOpen JDBC driver for a DB2 Universal database. I have very little experience with SQL beyond simple statements.
From this question, I see that the error I'm getting (SQL7008) is thrown when trying to "insert/update rows in a non-journaled table during a transaction" (paraphrased).
According to the project lead, our DB is not journaled and won't be any time soon (don't ask me why, I'm not the DBA). However, I'm working on a project where being able to commit everything in one go (rather than AutoCommit-ing each time an execute is called) is nearly necessary (not totally required, but it would solve a lot of issues down the road).
Is there any way to work around erorr SQL7008 without enabling Journalling?
The only way to work around it without enabling journaling is to disable transaction isolation in your connection string as follows:
jdbc:as400://systemname;naming=sql;errors=full;transaction isolation=none;date format=iso
The full list of JDBC properties can be found in the IBM Toolbox for Java JDBC properties documentation.
I have found that using WITH NONE at the end of the DB2 statement solve the problem, only if you use INSERT.
When I try using SET OPTION COMMIT=*NONE on a Delete statement, it seems to skip the where, and it deletes everything, the same happens when i try to use WITH NC or WITH NONE
To resolve this issue, do one of the following:
Enable journaling for the database table: Windows: Add a CLI Parameter 'TxnIsolation' with the value '32' within
your ODBC settings under "Administrative Tools". This option can be
found under: "Data Source" -> "Advanced Settings" -> "Add" ->
"TxnIsolation" as a radio button "No Commit".
AIX / Unix: Run the following DB2 command on your database: ' db2
update cli cfg for section using TXNIsolation 32'. Verify
these settings with the following command: ' db2 get cli cfg'
Alternate SQL workaround: (not OS-specific): Add 'WITH NONE' to the end
of your SQL UPDATE command.
More info...
There is an option that can be added to your connection string that disables commitment control.
Probably CommitMode=0 would work.
The official listing of SQL7008 is here (do CTRL-F for SQL7008). It looks like you can get more information from the reason code. If you're getting reason code 3, it looks like there is no other option besides enabling journaling.
If you're getting something other than reason code 3, then I guess you have more options.
Hope that helps.
If working on CL commands. The follow command solves the issue:
RUNSQLSTM SRCFILE(LIBNAME/SRCFILE) SRCMBR(MBRFILE) COMMIT(*NONE) NAMING(*SQL)
This is a particularly annoying problem I'm having, and I can't be the only one to have issue with it.
In NetBeans, when you type part of a method, then hit CTRL-SPACE, it displays the code-completion popup, whereupon you can hit tab to finish out the word. This is great, and pretty much how all IDE's operate.
Example:
Thread.sl
< CTRL-SPACE >
Thread.sleep
Yay!
Problem is that in this context, once you type in a paren, it auto-fills the parameters for the method with their default names, and inserts a closing paren (regardless of whether you have disabled the option to automatically close them on the preferences page for code completion). This behavior is NOT present if you had manually typed out the full name.
How is this helpful to anyone? You've got to type over it your actual variable that you will be passing, and NetBeans gives you no option to prevent the closing paren on code-completion.
Does anyone have a way to solve this issue, without having to dive into the netbeans source and build it just for this minor of an issue?
inserts a closing paren (regardless of
whether you have disabled the option
to automatically close them on the
preferences page for code completion).
That option is for brackets, not parentheses.
Does anyone have a way to solve this
issue, without having to dive into the
netbeans source and build it just for
this minor of an issue?
Remove the opening parenthesis from the list of completion selectors.
alt text http://img411.imageshack.us/img411/7287/netbeanscodeassist.png
What version of netbeans do you use ?
For me (NB 6.9 RC1), when I code complete a method with parameter, I can edit one by one all parameters with RETURN to go from one to another. It's very easy, and the suggestings parameters are 1/2 times corrects.
See Suggesting Parameters at Code Assistance in the NetBeans IDE Java Editor: A Reference Guide / Smart Code Completion