2012-09-06 73 views
1

我試圖從HSQLDB 2.2.8查詢數據與春天JDBC 3.1.2.RELEASE,這裏的語句:春天JDBC查詢之間date從HSQLDB

"SELECT id, account_id, operator_id, amount, currency_type, date 
    FROM account_entries WHERE account_id=? AND date BETWEEN DATE '?' AND DATE '?' + 1 DAY" 

屬性是:

1 (java.lang.Integer) 
2012-09-06 (java.sql.Date) 
2012-09-06 (java.sql.Date) 

錯誤我收到:

PreparedStatementCallback; SQL [SELECT id, account_id, operator_id, amount, 
currency_type, date FROM account_entries WHERE account_id=? 
AND date BETWEEN DATE '?' AND DATE '?' + 1 DAY]; data exception: 
invalid datetime format; nested exception is java.sql.SQLDataException: 
data exception: invalid datetime format 
+0

爲什麼需要圍繞佔位符引用日期? – Vikdor

+0

@Vikdor:如果沒有它們,我會得到另一個異常:「PreparedStatementCallback;錯誤的SQL語法[...];嵌套的異常是java.sql.SQLSyntaxErrorException:意外的令牌:?required:AND」 –

回答

2

必須要麼丟棄日期轉換:

... date BETWEEN ? AND ? + 1 DAY ...

或留住他們,但傳遞的參數正確格式化字符串(YYYY-MM-DD),而不是java.sql.Date對象。

+0

地獄,是啊!問題在於日期轉換。 –