gpt4 book ai didi

java - 如何处理PreparedStatement中的单引号?

转载 作者:行者123 更新时间:2023-12-02 00:56:25 27 4
gpt4 key购买 nike

我想使用一个准备好的语句,如下所示:

acl = conn.prepareStatement("INSERT INTO acls_t(user,topic,rw) values((SELECT id from users_t where username=?),'?/#',1);");
mqtt_acl.setString(1, name);
mqtt_acl.setString(2, uuid);

我的数据库是MariaDB,不接受这个。它返回以下错误:

java.sql.SQLException: Could not set parameter at position 2 (values was '3aa4ea54-3105-47a3-9bfb-c17c4348d84a')
Query - conn:56(M) - "INSERT INTO acls_t(user,topic,rw) values((SELECT id from users_t where username=?),'?/#',1);"

我该如何处理这个问题?

最佳答案

按如下方式进行:

acl = conn.prepareStatement("INSERT INTO acls_t(user,topic,rw) values((SELECT id from users_t where username=?),?,1);");
mqtt_acl.setString(1, name);
mqtt_acl.setString(2, uuid + "/#");

关于java - 如何处理PreparedStatement中的单引号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61325527/

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