I am trying to run multi-statement queries using JDBC on DB2 10.1 Windows but it fails with a syntax error. Following is the query-
SELECT * FROM schemaname.tablename;
Exception in thread "main" com.ibm.db2.jcc.am.SqlSyntaxErrorException: An unexpected token "" was found following "". Expected tokens may include: "schemaname.tablename".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.13.127
I understand that this comes due to the semi-colon at the end of the query which is not understand by the database. How can I set the query separator as semicolon so get through this.
With JDBC you execute one statement at a time; by the looks of it DB2 doesn't support it. Some drivers/databases have a way around this, but it is non-standard.
So instead of trying to execute two statements in one go, you will need to execute them one after the other.
Related
I try to use golang and query data from Oracle. My SQL query is:
SELECT * FROM TABLE1 OFFSET 10 ROWS;
But it gives an error:
EXTRA *errors.withStack=dpiStmt_execute: ORA-00933: SQL command not properly ended
My SQL query works fine when I query in SQL*Plus, but errors when I use golang.
I'd try running the query without the terminating semicolon, as Alex Poole pointed out. A lot of Oracle client libraries (i.e. cx_Oracle in python, ADO.NET Oracle Libraries) do complain if you try to execute a query ending with the semicolon (which is perfectly legal in SQL/Plus)
If the offset is not specified, it is assumed that it is 0 (zero). So, remove that clause (as it does nothing in your case), i.e.
select * from table1
and use that query in golang.
I am pretty sure that just your closing semicolon is to much. The semicolon is a character to separate several SQL statements or to close a pl/sql block. So when you write it at the end of a SQL statement the parser doesn't know how to handle it, cause he only awaits a single SQL statement.
I have a jMeter 3.0 to oracle 12 c using thin connection (used ojdbc 7 and 7_c) and I cannot use the row end line ( ; ). It always returns
Cannot create PoolableConnectionFactory (ORA-00933: SQL command not properly ended
If I remove the ";" from the query everything goes fine. How can I fix this?
I found a workaround for this that avoids having the semi-colon problem:
JDBC Request Query Type needs to be: Update Statement
The query needs to be processed as a block
BEGIN
SQL Statement
END;
There are specific SQL structures that can't be executed as a block but still this enables having legit SQL code within the request and enhances having several statements in the same request.
If you are using JDBC_Request Sampler, you should NOT keep semi-colon as a trailing at the end of a line for SQL query,
Do not enter a trailing semi-colon.
so, without semi-colon, it should work properly and no need to include that.
Reference:
http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
I have a query starting with REPLACE. When I use it directly in MySQL console everything is fine, so query is ok. However, when I put it in my code like this:
#Query("REPLACE INTO WeekAggregate...
There is an error:
web - 2016-10-05 10:35:44,297 [localhost-startStop-1] ERROR o.h.hql.internal.ast.ErrorCounter - line 1:1: unexpected token: REPLACE
antlr.NoViableAltException: unexpected token: REPLACE
How could I fix this? Is REPLACE not supported in HQL?
HQL is trasversal to underlying DBMS. So some functions you're using in your SQL can't be interpretated by HQL.
You have two ways:
change your HQL query (in this case you can rewrite your query with an DELETE/INSERT statement)
you can write your query in SQL and you can use a method createSqlQuery so the interpreter, runs the query as SQL native query.
I changed my query to native SQL query by using nativeQuery = true flag.
I am running one jmeter script to read data from Database (using JDBC Request). Here I am getting following error if I am running script in Jmeter3.0.
Cannot create PoolableConnectionFactory (ORA-00936: missing expression
)
But same script is running fine with jmeter2.13.
Do I need to change any property values?
Just modify Validation query in JDBC Connection Configuration to select 1 from DUAL as per documentation:
A simple query used to determine if the database is still responding. This defaults to 'SELECT 1' which is suitable for many databases. However some may require a different query; for example Oracle requires something like 'SELECT 1 FROM DUAL'. Note this validation query is used on pool creation to validate it even if "Test While Idle" suggests query would only be used on idle connections. This is DBCP behaviour.
I'm using Liquibase to create tables in DB2. I have a simple example changelog that tries to drop and then create a table.
The SQL statements work fine via my DbVisualizer tool (which uses the same JDBC driver as Liquibase) and also works fine when submitted via the db2 command line tool.
Here's the Liquibase input file:
--changeset dank:1 runAlways=true failOnError:false
DROP TABLE AAA_SCHEMA.FOO
--changeset dank:2 runAlways=true
CREATE TABLE AAA_SCHEMA.FOO ( MYID INTEGER NOT NULL )
Here's the error message I get:
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error:
SQLCODE=-104, SQLSTATE=42601, SQLERRMC=DROP TABLE AAA_SCHEMA.FOO;
;, DRIVER=4.18.60
The IBM error code -104 is about syntax problems. Based on looking at the error message my guess is that it has something to do with the end of line character ";". But I've tried the query with and without the semi-colon. The semi-colon is accepted by IBM's own db2 too, so it seems like a valid choice.
Any help in figuring out the cause of this error is much appreciated.
The problem was me forgetting to start my native sql file with this required line:
--liquibase formatted sql
Doh!