gpt4 book ai didi

java - SQL 仅替换为一行中的前两列

转载 作者:行者123 更新时间:2023-11-29 07:44:44 24 4
gpt4 key购买 nike

我目前拥有的是:

PreparedStatement ps = getSQLConnection().prepareStatement(
"REPLACE INTO " + table + " (uuid,name) VALUES(?,?)"
);

ps.setString(1, uuid.toString());
ps.setString(2, name.toLowerCase());
ps.executeUpdate();

但是它不仅仅设置索引 1 和 2,而是清除其他列值。如何插入仅包含前 2 个索引的行,并保持其他值不变?

该表是使用以下语句创建的:

"CREATE TABLE IF NOT EXISTS data (" +
"`uuid` varchar(36) NOT NULL," +
"`name` varchar," +
"`owner` varchar," +
"`tags` varchar," +
"PRIMARY KEY (`uuid`));"

最佳答案

来自the documentation :

REPLACE is a MySQL extension to the SQL standard. It either inserts, or deletes and inserts. For another MySQL extension to standard SQL—that either inserts or updates—see Section 13.2.5.3, “INSERT ... ON DUPLICATE KEY UPDATE Syntax”.

关于java - SQL 仅替换为一行中的前两列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28123999/

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