ERROR: relation does not exist - java

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.

Related

when i put \dt command it s not showing me any table

I don't understand what's wrong and why the program is not working.
I am watching a tutorial for spring boots beginners Java framework and I got stuck at this 2 errors from the pictures . And I really don't understand why it's appearing. I have a problem with database even if i connect in terminal when i put \dt command it s not showing me any table, and another error when i run the program, and i don t understand why I am doing wrong.
\dt shows all tables on your search_path. You can specify an argument that is a pattern that matches table names. To display all tables (including system catalogs and other internal data), use
\dt *.*

How to find errors in large Eclipse program

I've got a rather large program that interacts with a MySQL database. I recently changed the structure of the database considerably, but I thought I had made all of the necessary changes to my program to compensate for those database changes, but clearly I haven't.
I just recently several error messages, the first of which is this:
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
Strangely, though, it doesn't give tell me in which file this error came from (as a typical stacktrace would), let alone on which line number. How can I figure out from where this is coming?
I have a lot of calls to the database in this program, most of which deal with a Timestamp column. And I'm afraid that, while I have been using Eclipse for months now, I still have yet to use its Debug perspective. How can I use that?

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)

How to Set CSSID in jdbc db2 using java

My current task is to migrate a remote database to a localhost database. Everything seems fine up to now. The problem is when I'm checking whether the data are the same, data in my localhost weren't copied correctly. Japanese, Chinese and Arabic Characters were all question marks with boxes. I've searched the net and I've come to understand that it has something to do with the encoding scheme. I've checked the syntax, but none of them seem to work for me.
Can you provide me how to do it using JAVA?
NOTE: I seem to have a problem altering the database, (i think i don't have the permission ) so i would like to know if setting cssid in the tablespace is applicable.
When I once had trouble with encodings in DBs it was of a missing param in the commandline of my app:
java ... -Dfile.encoding=UTF-8 ...
The problem could come from the database codeset which permits to define the type of characters you are entering. However, it cannot be canged once the database was created.
Also, a normal column could not support graphic characters. Probably, you need to use a column that support graphic characters like: Graphic, vargraphic or dbclob

Categories