ひがやすを技術ブログ

電通国際情報サービスのプログラマ

PreparedStatement.setObject()

java.util.Dateの場合、setObjectではエラーになってしまうようです。
ラクルでも、HSQLDBでも同じ。


if (bindVariable != null) {
if (bindVariable.getClass().equals(java.util.Date.class)) {
java.util.Date d = (java.util.Date) bindVariable;
bindVariable = new Timestamp(d.getTime());
} else if (bindVariable instanceof Calendar) {
Calendar c = (Calendar) bindVariable;
bindVariable = new Timestamp(c.getTime().getTime());
}
ps.setObject(i + 1, bindVariable);
} else {
ps.setNull(i + 1, Types.VARCHAR);
}
とする必要がありそう。
Sqletはだいじょうぶ。
DbUtilsは、2004-01-13版はまだ直ってないようでした。
使ってないのにバグレポートするのもどうかと思って
今のところ様子見です。