我正在使用JDBI v2库将数据向上插入MySQL。我的任务是在不存在“ id”的情况下插入新行,或者在更新数据时进行更新,如下所示:
@SqlBatch("insert into saved_game.<table>(id, data, play_time) values (:id, :data, :playTime) on duplicate key update "
+ "data = if(play_time < values(play_time), values(data), data), play_time = if(play_time < values(play_time), values(play_time), play_time)")
@BatchChunkSize(1000)
public abstract void insert(@Define("table") String table, @BindBean Collection<SavedGameBean> beans);
但是在运行时会引发异常:
Caused by: java.sql.BatchUpdateException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1819) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1281) ~[mysql-connector-java-5.1.35.jar:5.1.35]
at snaq.db.CachedStatement.executeBatch(CachedStatement.java:435) ~[dbpool-7.0.1-jdk7.jar:?]
at org.skife.jdbi.v2.PreparedBatch.internalBatchExecute(PreparedBatch.java:196) ~[jdbi-2.77.jar:2.77]
... 41 more
我该如何解决?