0
votes

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.

1
What is this "multistatement query" that you are talking about? May be you could show some of your code that causes the error? - mustaccio
It is basically of the form SELECT * FROM schemaname.tablename1;SELECT * FROM schemaname.tablename2; Two queries separated by a semicolon. However, my requirement isn't exactly that. I need to run a query that ends with semicolon as they are coded that way and run fine with DB2 for z/OS, I need to run the same with DB2 for Windows. I don't have the option to alter the queries. - User2709
Neither of these is possible. You can only issue one statement at a time, unless using a compound statement, and it should not have any terminators (because terminators are not part of the SQL syntax). - mustaccio

1 Answers

0
votes

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.