Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java中sql准备语句的问题_Java_Sql - Fatal编程技术网

java中sql准备语句的问题

java中sql准备语句的问题,java,sql,Java,Sql,尝试使用where子句和预处理语句在表(事件)中设置值时,我的sql语法出错 这是代码` public void setEventParticipants(int id, String eventParticipants) { try { String req1="insert into events (eventParticipants) values(?) where (eventId)=?"; Prepare

尝试使用where子句和预处理语句在表(事件)中设置值时,我的sql语法出错 这是代码`

public void setEventParticipants(int id, String eventParticipants)
    {

            try {
            String req1="insert into events (eventParticipants) values(?) where (eventId)=?";
            PreparedStatement pre = c.prepareStatement(req1);
            pre.setString(1, eventParticipants);
            pre.setInt(2, id);
            pre.executeUpdate();

        } catch (SQLException ex) {
            Logger.getLogger(EventService.class.getName()).log(Level.SEVERE, null, ex);
        }
    }`
我得到了这个错误: 您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解第1行“where(eventId)=7”附近使用的正确语法 感谢您的帮助

更改此设置

insert into events (eventParticipants) values(?) where (eventId)=?
对此

UPDATE events SET eventParticipants = ? WHERE eventId = ?
如果执行insert语句,它应该填充您的表

insert into events (eventParticipants) values(?) where (eventId)=?
对此

UPDATE events SET eventParticipants = ? WHERE eventId = ?

如果执行insert语句,它应该填充表,而不是insert INTO table_name 值(值1、值2、值3等); 试一试 更新表名称 设置column1=value1,column2=value2。。。 何处条件; 或 插入到表\u名称中
值(&value1、&value2和&value3,…)

而不是插入到表\u名称中 值(值1、值2、值3等); 试一试 更新表名称 设置column1=value1,column2=value2。。。 何处条件; 或 插入到表\u名称中
值(&value1、&value2和&value3,…)

您的SQL是错误的。请阅读有关INSERT语句和更新的MySQL文档,以及如何使用这些语句和更新的示例。INSERT不能用于更新现有行

我怀疑正确的说法是

update events set eventParticipants = ? where eventId = ?

但这取决于您试图实现的目标。

您的SQL是错误的。请阅读有关INSERT语句和更新的MySQL文档,以及如何使用这些语句和更新的示例。INSERT不能用于更新现有行

我怀疑正确的说法是

update events set eventParticipants = ? where eventId = ?

但是这取决于你想要实现什么。

你不应该尝试运行
更新而不是
插入
?你不应该尝试运行
更新而不是
插入
?谢谢我觉得用插入代替更新很愚蠢,但是谢谢。我会尽快设置为答案如果确实对您有帮助,请不要忘记接受,因为其他人可能会遇到与您相同的问题:)谢谢我觉得使用insert代替update很愚蠢,但谢谢。如果我能帮到你,请不要忘记接受,因为其他人可能会遇到与你相同的问题:)