执行查询时DB2 SQLSTATE 42601

时间:2013-05-29 10:44:34

标签: java db2 sqlexception

我有一个存储在文件中的sql-query。 以下是查询的开头:

merge
    into SCHEMA.TABLE as A
    using (
        values (599999991, '2012-12-31',......

我有一个Java应用程序并将查询加载到String对象中 - 没关系。然后我做以下事情:

private static final String DRIVER = "com.ibm.db2.jcc.DB2Driver";
...
Class.forName(DRIVER);
...
Connection connection = DriverManager.getConnection(location, user, password);
preparedStatement = connection.prepareStatement(queryString);
return preparedStatement.executeUpdate();

正确加载queryString。 preparedStatement也应该没问题 - 我在查询中没有任何参数。 但我有一个例外:

com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -104, SQLSTATE: 42601,   SQLERRMC: into SCHEMA.TABLE as A    using (        values (599;merge    ;<space>
at com.ibm.db2.jcc.c.tf.e(tf.java:1680)
at com.ibm.db2.jcc.c.tf.a(tf.java:1239)
at com.ibm.db2.jcc.b.jb.h(jb.java:139)
at com.ibm.db2.jcc.b.jb.a(jb.java:43)
at com.ibm.db2.jcc.b.w.a(w.java:30)
at com.ibm.db2.jcc.b.cc.f(cc.java:161)
at com.ibm.db2.jcc.c.tf.n(tf.java:1219)
at com.ibm.db2.jcc.c.uf.gb(uf.java:1816)
at com.ibm.db2.jcc.c.uf.d(uf.java:2298)
at com.ibm.db2.jcc.c.uf.Y(uf.java:540)
at com.ibm.db2.jcc.c.uf.executeUpdate(uf.java:523)
at com.epam.sbrf.db.DBUtil.executeUpdateQuery(DBUtil.java:93)
at com.epam.sbrf.db.DBUtil.executeUpdateQuery(DBUtil.java:77)
at com.epam.sbrf.test.AggregateTest.BeforeTest(AggregateTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:564)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:213)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:138)
at org.testng.TestRunner.beforeRun(TestRunner.java:641)
at org.testng.TestRunner.run(TestRunner.java:609)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)

在我的sql-query中,我得到了“599; merge;”而不是“599999991”

我用谷歌搜索了这个错误,这是解释:

Short Description: ILLEGAL SYMBOL SOME SYMBOLS THAT MIGHT BE LEGAL ARE

A syntax error was detected where the symbol ?token? occurs in the SQL statement. The list of symbols that might be legal shows some alternate symbols that could possibly be correct at that point, if the preceding part of the statement is entirely correct. However, the preceding part of the statement might be incorrect. For example, if an important keyword is omitted, DB2 detects the error later, and not always immediately after the point where the keyword should appear. The list of alternate symbols are only suggestions. Some of those symbols might not even be legal for statements to be executed by DB2. Those symbols are possibly correct for statements sent to other database management systems. This SQL code will also be issued if the RELEASE TO SAVEPOINT statement is specified without a savepoint name. System action: The statement cannot be executed. Programmer response: Correct the statement and execute it again.

所以,我不明白问题的来源。我试着在SquirrelSql中执行这个sql脚本 - 它有效。在我的应用程序中,我有一个正确的字符串,其中包含查询的文本。当我尝试基于此查询执行Statement时,我收到此错误。有人遇到过这样的问题吗?

更新 我已经将文件的编码更改为UTF-8(旧的 - 没有BOM的UTF-8)。现在我得到了:     DB2 SQL错误:SQLCODE:-104,SQLSTATE:42601,SQLERRMC:PAY;合并到; JOIN

0 个答案:

没有答案