为什么我使用DB2 LUW和WebSphere App Server获得SQLCODE = -204,SQLSTATE = 42704?

时间:2014-06-10 15:09:37

标签: java database db2 websphere

有许多网页,人们将此消息显示为症状(SQLERRMC之后的值和驱动程序级别不同):

DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=M51Dev.CUSTOMER, DRIVER=3.61.65

here上包含多个StackOverflow

错误代码表示找不到对象 - 几乎总是表 - ,SQLERRMC参数的值包含相关对象的名称。在我可以发现的每一次出现中,解决方案只是他们需要使用模式名称限定表名。但是,正如您从上面的行中所看到的,这不是这里的情况。架构为M51Dev,表格为CUSTOMER,两者都存在。

环境是WebSphere Application Server(在这种特殊情况下为7.0.0.31,但我有点怀疑它是否相关)在Windows Server 2003 R2上运行,旧的XP机器上运行DB2 9.7.300.3885。数据源在WAS中定义,并通过JNDI检索。应用程序是用Java编写的,我们的SQL是通过Spring的JdbcTemplate s使用JDBC执行的。

WAS中的数据源定义包括一个名为currentSchema的自定义属性,该属性设置为M51Dev

这是SQL的相关行(或者其中之一,因为我们得到每个表的相同症状):

SELECT rundateOverride  FROM customer WHERE customerId=1

这是堆栈跟踪的摘录。如果有帮助,我可以提供更多。

bad SQL grammar [SELECT rundateOverride  FROM customer WHERE customerId=1]; nested exception is com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=M51Dev.CUSTOMER, DRIVER=3.61.65
    at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:233)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:406)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:455)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:463)
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:471)
    at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:476)
    at com.misys.meridian.runtime.userPromptable.SchedulerService.refreshMarketCentreSystemDates(SchedulerService.java:1539)
    at com.misys.meridian.runtime.userPromptable.SchedulerService.performService(SchedulerService.java:270)
    at com.misys.meridian.runtime.userPromptable.SchedulerService.prompt(SchedulerService.java:175)
    at com.misys.meridian.runtime.userPromptable.GenericDelegate.process(GenericDelegate.java:95)
    at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:71)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.DelegateAsyncProcessor.processNext(DelegateAsyncProcessor.java:99)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:91)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler(RedeliveryErrorHandler.java:333)
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:223)
    at org.apache.camel.processor.RouteContextProcessor.processNext(RouteContextProcessor.java:45)
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:90)
    at org.apache.camel.processor.interceptor.DefaultChannel.process(DefaultChannel.java:304)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73)
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)
    at org.apache.camel.processor.Pipeline.access$100(Pipeline.java:43)
    at org.apache.camel.processor.Pipeline$1.done(Pipeline.java:135)
    at org.apache.camel.processor.ThreadsProcessor$ProcessCall.run(ThreadsProcessor.java:56)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:450)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:314)
    at java.util.concurrent.FutureTask.run(FutureTask.java:149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:906)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:929)
    at java.lang.Thread.run(Thread.java:761)
Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=M51Dev.CUSTOMER, DRIVER=3.61.65
    at com.ibm.db2.jcc.am.ed.a(ed.java:676)
    at com.ibm.db2.jcc.am.ed.a(ed.java:60)
    at com.ibm.db2.jcc.am.ed.a(ed.java:127)
    at com.ibm.db2.jcc.am.gn.c(gn.java:2554)
    at com.ibm.db2.jcc.am.gn.d(gn.java:2542)
    at com.ibm.db2.jcc.am.gn.a(gn.java:2034)
    at com.ibm.db2.jcc.t4.cb.g(cb.java:140)
    at com.ibm.db2.jcc.t4.cb.a(cb.java:40)
    at com.ibm.db2.jcc.t4.q.a(q.java:32)
    at com.ibm.db2.jcc.t4.rb.i(rb.java:135)
    at com.ibm.db2.jcc.am.gn.gb(gn.java:2005)
    at com.ibm.db2.jcc.am.gn.a(gn.java:3023)
    at com.ibm.db2.jcc.am.gn.a(gn.java:667)
    at com.ibm.db2.jcc.am.gn.executeQuery(gn.java:651)
    at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeQuery(WSJdbcStatement.java:999)
    at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:440)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:395)
    ... 40 more

正如一些背景知识:这是一个支持多个数据库平台的银行应用程序。我们使用各种版本的Oracle,MS SQL Server和DB2 for System i,拥有多年的使用经验;但我们使用DB2 LUW相对较新。尽管如此,我的一些同事仍然使用上述配置,至少在同一台机器上安装了WAS和DB2时。

我可以在拥有WAS的计算机上运行SQL客户端,并使用相同的参数连接到相关数据库并成功查询,包括使用SET SCHEMA M51Dev而不是限定表名,我认为最接近模拟JDBC / JNDI环境。

1 个答案:

答案 0 :(得分:12)

答案是区分大小写。

这个答案实际上是由mustaccio中的comment提供的,但他们似乎并不想将其添加为答案。如果你看到这个,@ mustaccio,请添加你自己的答案,所以我可以接受。

无论如何,事实证明,WAS似乎有效地将引号括在您在“自定义属性”部分中指定的值。我已为M51Dev属性输入currentSchema,并将其作为"M51Dev"发送给DB2。但DB2已将模式名称存储为M51DEV它将这些视为两个不同的值,当然......

为属性值指定M51DEV解决了问题。