Intellij IDEA SQL autocomplete quotes - java

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.

Related

ERROR: relation does not exist

So here is the problem. I am scraping some data with java and eventually i place that java into postgres database. When i run Java program, i get error ERROR: relation "table name" does not exist but when i personally write that same query in PGAdmin III, it works fine. I googled it and it's not about caps letters that most people have problems with. Here is a screenshot:
My first thought was that you were using double quotes for values, but then I looked again and realized you were assembling a query using string concatenation.
DON'T DO THAT. In addition to making these problems impossible to debug you open yourself up to sql injection.
In debugging something like this, you should first port to use placeholder syntax (which PostgreSQL's JDBC driver supports) and then, if that doesn't work, then post the server logs.

I can't figure out how to disable Netbean's code completion without disabling pop-up of suggested code

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

Tracing the source of - java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement

I got that error when I ran my Java-Oracle 11g-JDBC code in eclipse. I am only trying to create a table and then add some rows to it.
How can I see which line of code caused that error ?
Please help.
If you can, run the SQL you are attempting to execute directly against the Oracle database, outside of Java. You will get a more meaningful error message using something like SQL Developer. Fix the SQL there before patching your code.
If you are creating a table and adding rows to that table, do all these in a stored procedure with IN and OUT parameters, compile the stored procedure (by doing so eliminates all errors) and call this procedure from Java.
This would be helpful in debugging and making code neat and tidy.
Regards

SQL7008 Error - Workaround?

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)

SQL validation in IntelliJ IDEA: How to turn it off?

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.

Categories