我是駱駝新手,我嘗試處理SQL數據。如果SQL消耗(選擇)完成,我嘗試更新消費的行,但我只是得到一個「錯誤的SQL語法」異常。如何使用Apache Camel SQL組件更新僅消耗的SQL行?
我使用Apache Camel SQL-Component,其中起始端點是一個sql select語句。爲了將它們標記爲已消耗,我使用SQL-Component的onConsume
參數。在選擇中,v_table
是原始表t_table
的視圖,在更新後使用。所以v_table
和t_table
中的一排id
是一樣的。要更新t_table
中的所有行,我使用where條件與where id = :#id
。
String sqlSelect = "select * from v_table where camel_is_read = 0";
String sqlUpdate = "update t_table set camel_is_read = 1, date_checked = sysdate where id = :#id";
from("sql:"+sqlSelect+"?dataSource=myDataSource&onConsume="+sqlUpdate)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println(exchange.getIn().getBody().toString());
}
})
.errorHandler(deadLetterChannel("direct:moveFailedOut").useOriginalMessage())
.bean("orderToJms")
.to(jmsURI)
.bean("validate")
.to(ftpOut);
如果我執行此,我得到的follwoing例外:
WARN Error executing onConsume/onConsumeFailed query update t_table set camel_is_read = 1, date_checked = sysdate where id = :?id. Caused by: [org.springframework.jdbc.BadSqlGrammarException - PreparedStatementCallback; bad SQL grammar [update t_table set camel_is_read = 1, date_checked = sysdate where id = ?]; nested exception is java.sql.SQLSyntaxErrorException: ORA-00904: "YSDATEHERE": ungültiger Bezeichner
]
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [update t_table set camel_is_read = 1, date_checked = sysdate where id = ? exception is java.sql.SQLSyntaxErrorException: ORA-00904: "YSDATEHERE": ungültiger Bezeichner
at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:237)
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:605)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
at org.apache.camel.component.sql.DefaultSqlProcessingStrategy.commit(DefaultSqlProcessingStrategy.java:46)
at org.apache.camel.component.sql.SqlConsumer.processBatch(SqlConsumer.java:195)
at org.apache.camel.component.sql.SqlConsumer$1.doInPreparedStatement(SqlConsumer.java:118)
at org.apache.camel.component.sql.SqlConsumer$1.doInPreparedStatement(SqlConsumer.java:91)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:589)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
at org.apache.camel.component.sql.SqlConsumer.poll(SqlConsumer.java:91)
at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "YSDATEHERE": ungültiger Bezeichner
我試圖用一個測試ID執行手動數據庫更新(例如,「3」),它的工作原理,所以一般的SQL語法應該沒問題。所以在我看來,駱駝不能取代:#id
參數。
我添加了一個處理器,檢查選擇的結果:
{ID=3, [...] CAMEL_IS_READ=0}
在這裏,我可以看到,選擇成功擦肩而過,必要id
。我不明白爲什麼駱駝不能取代:#id
參數與id
值3.有誰知道如何解決這個問題?我使用this和this作爲粗略示例/模板。或者這種方法一般是錯誤的?
sysdate應該是大寫嗎? –
嗨@ClausIbsen,謝謝你的回覆(我喜歡你的書:)。我其實用SYSDATE而不是sysdate來嘗試它,但它沒有顯示效果。我也直接在我的oracle數據庫中嘗試了整個更新語句,它在哪裏工作。它也沒有id參數(但這不是目標,我只想更新處理的行)。 – Zeussi
什麼版本的駱駝。你可以嘗試升級。 –