SQL7008 Error - Workaround? - java

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)

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.

JPA Cannot resolve column/IntelliJ

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!

Intellij IDEA SQL autocomplete quotes

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.

Java Updatable Resultset Anomaly with UTF-8 data in English Windows

I am facing a weird problem. I am getting exception when I try to update or delete row in updatable resultset which contains non-english utf-characters. However insert goes fine.
java.sql.SQLException: refreshRow() called on row that has been deleted or had primary key changed.
The weirdest things are:
This error happens only when compiled jar is run in windows
However same jar run in Linux runs fine for same data without problem.
Same project run from within IDE runs also fine in Windows.
Other information in case that will be helpful
OS: Windows XP (English with non-english language support installed)
DB: MySQL, encoding utf8, collation - utf8_general_ci
IDE: Netbeans 6.9.1
JDK: 6 update 23
Connector/J 5.1.15 (Just switch to check if this works but same problem with version 14 too)
Connection string includes: "useUnicode=true" and "characterEncoding=utf8"
Initially thought that IDE has something to do so posted this message in netbeans forum
http://forums.netbeans.org/topic36558.html
Also cross posted in mysql JDBC forums hoping to find some answer
http://forums.mysql.com/read.php?39,408795,408795
but couldn't get any help there.
So far, the problem seems to be Windows. May be this is just minor issue but can't think of any work around.
Need some suggestion
Thanks and regards
Deepak
It seems like your IDE is override the default encoding that you get when you run your application from the command line. If you check the actual JVM arguments the IDE uses (normally available in the output window of your IDE), you will probably see the inclusion of a file-encoding argument, like this:
-Dfile.encoding="UTF-8"
Try to start your application with this JVM argument and see if it makes any difference, and if not - compare the actual encoding used when run from the IDE and on the command line like this:
System.out.println(System.getProperty("file.encoding"));
I had the same problem and solved it. I don't understand why this is happenning but this is caused when your primary key of mysql table is combined. In my database there are many tables that have combined primary key and others that have auto-increment. Likely i noticed that this problem didn't occur in tables with auto-increment primary key.

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