gpt4 book ai didi

java.sql.SQLException : near "on": syntax error problem

转载 作者:行者123 更新时间:2023-11-30 01:57:38 25 4
gpt4 key购买 nike

在 Sqlite 3.6.0 中,我想更新记录(如果存在或插入)。但是我收到错误

java.sql.SQLException: near "on": syntax error

我的sql查询如下;

INSERT INTO tx (
_id,
amount,
fee,
prev_hash,
nonce,
action_time,
completion_time,
_from,
_to,
asset,
hash,
block,
seq,
[desc]
)
VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
)
ON CONFLICT (
_id
)
DO UPDATE SET amount = 1.0,
fee = 0.001,
prev_hash = 'e6d0ca4b71488972cb149eef427ffbeb6132449c045c88db89ddaa8ab0c3611f',
nonce = 1544773280,
action_time = 1544773276808,
completion_time = 1544773276808,
_from = 'SKK1P5eQqoN7FBKnughbvp3UBK2CyjRQhHBp',
_to = 'SKK1KuAwe4kR1SfdoXDiQStVtRPvdTVaKy2ry',
asset = 'SKK',
hash = '',
block = 100,
seq = 15288,
[desc] = 'denemee'

我的代码块如下;

sql = "insert into tx (_id,amount,fee,prev_hash,nonce,action_time,completion_time,_from,_to,asset,hash,block,seq,desc) "
+ "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?) on conflict (_id) do update set "
+ "amount =" + tx.amount + ",fee=" + tx.fee + ",prev_hash='" + tx.prev_hash
+ "'" + ",nonce=" + tx.nonce + ",action_time=" + tx.action_time
+ ",completion_time=" + tx.action_time + ",_from='" + tx.wallet + "'" + ",_to='"
+ tx.to + "'" + ",asset='" + tx.asset + "'" + ",hash=''" + ",block=100"
+ ",seq=" + tx.seq + ",desc='" + tx.desc + "'";
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, tx._id);
pstmt.setString(2, String.valueOf(tx.amount));
pstmt.setString(3, String.valueOf(tx.fee));// fee
pstmt.setString(4, tx.prev_hash);// prev_hash
pstmt.setString(5, tx.nonce);// nonce
pstmt.setString(6, String.valueOf(tx.action_time));// action time
pstmt.setString(7, "");// completion_time
pstmt.setString(8, tx.wallet);// from
pstmt.setString(9, tx.to); // to
pstmt.setString(10, tx.asset);// asset
pstmt.setString(11, tx.hash);// hash
pstmt.setString(12, "");// block
pstmt.setInt(13, tx.seq);// seq
pstmt.setString(14, tx.desc);// desc
pstmt.executeUpdate();

原始查询在sqlitestudio上成功运行,但我收到错误。我知道sqlite版本3.6.0支持upsert事件。我哪里做错了。如何正确处理这个问题。

最佳答案

您的问题是由于

I know that sqlite version 3.6.0 supports upsert event.

使用INSERT..... ON CONFLICT .... DO.... (称为 UPSERT)仅从版本 3.24.0 开始可用。

在 3.24.0 之前的版本中尝试使用 UPSERT (DO.....) 将导致 syntax error at ON

按照

UPSERT is a special syntax addition to INSERT that causes the INSERT to behave as an UPDATE or a no-op if the INSERT would violate a uniqueness constraint. UPSERT is not standard SQL. UPSERT in SQLite follows the syntax established by PostgreSQL. UPSERT syntax was added to SQLite with version 3.24.0 (2018-06-04).

An UPSERT is an ordinary INSERT statement that is followed by the special ON CONFLICT clause shown above.

SQL As Understood By SQLite - upsert

您需要使用 3.24.0 或更高版本的 SQLite 版本,或者寻找替代方法。

关于java.sql.SQLException : near "on": syntax error problem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53849174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com