行云无鸣

2008-04-08

继续昨日话题:DB2报sqlcode:-418

Filed under: 未分类 — 标签:, , , , , — hellyguo @ 19:11

今天又报了

完全没有想法了

在TOAD3.0Free中执行,报必须指定数据长度

结果就由:

CAST(#value# AS VARCHAR)

改为:

CAST(#value# AS VARCHAR(20))

但DECIMAL相关的,长度不指定就无所谓

CAST(#value# AS DECIMAL)

郁闷

20080409补记:
DECIMAL也必须指定精度,若不指定,将有可能报Overflow

2008-04-07

iBatis连接DB2报sqlcode:-418

Filed under: 未分类 — 标签:, , , — hellyguo @ 21:56

代码为:
UPDATE DEMOTAB
SET VAL = (
CASE FLAG
WHEN 1
THEN #min#
WHEN 0
THEN #max#
END)
WHERE PUB=1

结果运行报错:

— Cause: com.ibm.db2.jcc.c.SqlException: DB2 SQL error: SQLCODE: -418, SQLSTATE: 42610, SQLERRMC: null

查找文档得知:

SQLCODE -418, Error: A STATEMENT STRING TO BE PREPARED CONTAINS AN INVALID USE OF PARAMETER MARKERS

结合http://www.javaeye.com/topic/58423所述,改为后,测试通过
UPDATE DEMOTAB
SET VAL = (
CASE FLAG
WHEN 1
THEN CAST(#min# as DECIMAL)
WHEN 0
THEN CAST(#max# as DECIMAL)
END)
WHERE PUB=1

结论:DB2中使用预编译语句,必须指定类型

%d 博主赞过: