我有一个存储在文件中的 sql 查询。这是查询的开头:
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 查询中,我得到“599;合并;” 而不是“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;merge into ;JOIN