I am executing an SQL query via jcc to run a report. When I opened the error log file for the program and examined the SQL query, everything seems to be fine (There are no extra or missing brackets, commas, etc and the syntax is good) however when I execute I am getting this error:
[Report.execute()] DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=,;ATE IN (1,2,3,10,1)
;, DRIVER=4.12.55
When I researched about the SQLCODE I found out that it means there is an illegal symbol in the query. What can I look for to find this illegal symbol?
This is the query
Sorry for the tiny font but if you zoom 200% or so you can see the query better.
Thanks a lot 
I’m trying to create temporary tables to do some testing and I’m facing this error:
[DECLARE - 0 row(s), 0.000 secs] [Error Code: -104, SQL State: 42601] DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=key;(
id int primary;<references_spec>, DRIVER=3.50.152
when trying to create 2 temporary tables with 1 foreign key, as follows:
declare global temporary table session.company (
id_comp int not null generated always as identity (start with 0 increment by 1),
name_comp varchar(60)
) with replace on commit preserve rows not logged;
delete from session.company;
declare global temporary table session.employee (
id_emp int not null generated always as identity (start with 0 increment by 1),
name varchar(40),
id_comp int,
constraint fk_id_comp
foreign key (id_comp)
references session.company (id_comp)
on delete cascade
) with replace on commit preserve rows not logged;
delete from session.employee;
If I remove the constraint part, it executes fine. I’ve tried both references session.company (id_comp) and references session.company.id_comp, with the same result.
How can I solve this?
Thanks in advance.
UPDATE:
It might be considered a different question but, as it was suggested that I generate id_comp as a PRIMARY_KEY in session.company, I can’t get it work this way neither.
I tried to create a table with a PRIMARY KEY in a new script with that simple table (as you can see, I tried to do it with the primary key constraint after a comma:
declare global temporary table session.t1 (
id int primary key generated always as identity (start with 0 increment by 1) -- ,
-- primary key (id)
) with replace on commit preserve rows not logged;
Also tried all this different options:
primary key id int generated always as identity (start with 0 increment by 1)
---
primary key (id) int
---
primary key id int
---
id int,
primary key (id)
and none of them works, all return `Error Code: -104′.
The SQL error sqlcode=-104 sqlstate=42601 is a syntax error that occurs in DB2 databases. It indicates that the SQL statement is not properly formed and could not be executed by the database server. This error can occur for a variety of reasons, including incorrect use of quotation marks, missing keywords, or incorrect syntax.
Method 1: Check Quotation Marks
To fix the DB2 SQL error sqlcode=-104 sqlstate=42601, you can use the «Check Quotation Marks» method. This error occurs when there is a syntax error in the SQL statement. Here is an example of how to use the «Check Quotation Marks» method:
- Check the SQL statement for any missing or extra quotation marks.
SELECT * FROM table WHERE column = 'value
In this example, there is a missing quotation mark at the end of the value.
- Add the missing quotation mark to the SQL statement.
SELECT * FROM table WHERE column = 'value'
Now the SQL statement is correct and the error should be fixed.
Here is another example:
- Check the SQL statement for any missing or extra quotation marks.
INSERT INTO table (column1, column2) VALUES ('value1, 'value2')
In this example, there is a missing quotation mark after value1 and an extra quotation mark after value2.
- Add the missing quotation mark and remove the extra quotation mark from the SQL statement.
INSERT INTO table (column1, column2) VALUES ('value1', 'value2')
Now the SQL statement is correct and the error should be fixed.
By using the «Check Quotation Marks» method, you can easily fix the DB2 SQL error sqlcode=-104 sqlstate=42601. Just make sure to check your SQL statement for any missing or extra quotation marks.
Method 2: Verify Keywords and Syntax
To fix the DB2 SQL error sqlcode=-104 sqlstate=42601 using Verify Keywords and Syntax, follow these steps:
- Open the SQL query that is causing the error.
- Identify the line number where the error occurred.
- Verify the syntax and keywords used in the SQL query.
- Make sure that all keywords are spelled correctly and that there are no typos.
- Check that all parentheses and quotation marks are properly closed.
- Verify that all table and column names are correct and exist in the database.
- Check that all data types and functions are used correctly.
Here are some examples of how to use Verify Keywords and Syntax to fix the DB2 SQL error sqlcode=-104 sqlstate=42601:
Example 1:
SELECT * FROM employees WHERE salary > 5000 AND department = 'Sales;
Error: DB2 SQL error sqlcode=-104 sqlstate=42601
Solution:
SELECT * FROM employees WHERE salary > 5000 AND department = 'Sales';
Explanation: The error was caused by a missing quotation mark at the end of the string ‘Sales’. The corrected query includes the missing quotation mark.
Example 2:
UPDATE employees SET salary = 6000 WHERE employee_id = 1234;
Error: DB2 SQL error sqlcode=-104 sqlstate=42601
Solution:
UPDATE employees SET salary = 6000 WHERE employee_id = '1234';
Explanation: The error was caused by using the wrong data type for the employee_id column. The corrected query includes quotes around the value to indicate that it is a string.
Example 3:
SELECT first_name, last_name, salary FROM employees WHERE salary > 5000 ORDER BY last_name DESC;
Error: DB2 SQL error sqlcode=-104 sqlstate=42601
Solution:
SELECT first_name, last_name, salary FROM employees WHERE salary > 5000 ORDER BY last_name DESC;
Explanation: The error was caused by a missing comma between the last_name and salary columns in the SELECT statement. The corrected query includes the missing comma.
By following these steps and using Verify Keywords and Syntax, you can easily fix the DB2 SQL error sqlcode=-104 sqlstate=42601 and ensure that your SQL queries are error-free.
To fix the DB2 SQL error with SQLCODE=-104 and SQLSTATE=42601, you can use trusted tools and debugging techniques. Here are the steps to follow:
-
Identify the cause of the error. The error code indicates a syntax error in the SQL statement. Check the SQL statement for any syntax errors such as missing or incorrect keywords, incorrect use of operators, or missing or incorrect punctuation.
-
Use a trusted SQL editor or IDE to write and test SQL statements. These tools typically have syntax highlighting and error checking features that can help you identify and fix syntax errors.
-
Use the DB2 command line processor (CLP) to execute the SQL statement. The CLP provides debugging options that can help you identify and fix errors. For example, you can use the «-z» option to enable tracing, which will generate a trace file that can help you identify the cause of the error.
-
Use the DB2 Control Center or IBM Data Studio to debug the SQL statement. These tools provide graphical interfaces that allow you to step through the SQL statement and view the values of variables and expressions.
Here is an example SQL statement with a syntax error:
The error is caused by the misspelling of the keyword «FROM». To fix the error, change «FORM» to «FROM»:
In conclusion, using trusted tools and debugging techniques can help you quickly identify and fix syntax errors in SQL statements. Remember to test your SQL statements thoroughly before executing them in a production environment.
Method 4: Consult the DB2 Documentation
To fix the DB2 SQL error sqlcode=-104 sqlstate=42601, you can consult the DB2 documentation for more information. Here are the steps to do it:
- Go to the IBM DB2 documentation website.
- Look for the SQL error codes section.
- Search for the error code sqlcode=-104 sqlstate=42601.
- Read the description and possible causes of the error.
- Look for the suggested solutions to fix the error.
Here are some sample code examples that you can use to fix the error:
- Check the syntax of your SQL statement:
SELECT * FROM mytable WHERE name = 'John'
- Use double quotes instead of single quotes for identifiers:
SELECT "name" FROM mytable
- Use the correct data type for your values:
INSERT INTO mytable (id, name, age) VALUES (1, 'John', 30)
- Use the correct syntax for your SQL function:
SELECT COUNT(*) FROM mytable
In conclusion, consulting the DB2 documentation can provide helpful information and solutions for fixing SQL errors. By following the steps outlined above and utilizing the provided code examples, you can successfully address the DB2 SQL error sqlcode=-104 sqlstate=42601.
Я выполняю SQL-запрос через jcc для запуска отчета. Когда я открыл файл журнала ошибок для программы и изучил SQL-запрос, все кажется прекрасным (никаких лишних или отсутствующих скобок, запятых и т.д. И синтаксиса хороши), однако при выполнении этой ошибки я получаю следующую ошибку:/p >
[Report.execute()] Ошибка DB2 SQL: SQLCODE = -104, SQLSTATE = 42601, SQLERRMC =,; ATE IN (1,2,3,10,1)
;, DRIVER = 4.12.55
Когда я исследовал SQLCODE, я узнал, что это означает, что в запросе есть незаконный символ. Что я могу найти, чтобы найти этот незаконный символ?
Это запрос
Извините за маленький шрифт, но если вы увеличиваете 200% или около того, вы можете лучше видеть запрос.
Большое спасибо:)


