【问题标题】:error in SQL syntax check the manual that corresponds to your MariaDB server?SQL 语法错误 检查与您的 MariaDB 服务器对应的手册?
【发布时间】:2019-05-29 06:59:14
【问题描述】:

我有以下更新查询我在查询中找不到错误

 public void updateContact(contact cont){
    
     Connection con=myConnection.getConnection();
    PreparedStatement ps ;
    try {
        // below is Query Check full line 
   String updateQuery=" UPDATE `mycontact` SET `firstName`=?,`lastName`=?,`group`=?,`phone`=?,`email`=?,`address`=?, WHERE `id`=?";

       ps=con.prepareStatement(updateQuery);
       ps.setString(1, cont.getFirstName());
       ps.setString(2, cont.getLastName());
       ps.setString(3, cont.getGroup());
       ps.setString(4, cont.getPhone());
       ps.setString(5, cont.getEmail());
       ps.setString(6,cont.getAddress() );
       ps.setInt(7, cont.getCid());
     
       if(ps.executeUpdate() !=0){
               JOptionPane.showMessageDialog(null, "contact Data Edited ");
           }else{
                       JOptionPane.showMessageDialog(null, "Somthing Wrong");

               }       
       
    } catch (SQLException ex) {
        System.out.println("err in  update query");
        Logger.getLogger(contactQuery.class.getName()).log(Level.SEVERE, null, ex);
    }

}

Front.contactQuery 更新联系人

严重:无

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 你有错误

在您的 SQL 语法中;查看与您的 MariaDB 服务器对应的手册

【问题讨论】:

  • “where”前多了一个逗号:address=?, WHERE

标签: java netbeans phpmyadmin


【解决方案1】:

去掉地址后面的逗号:

`address`=?,

SQL 不能忽略末尾的额外逗号。因此,在复制粘贴编辑 SQL 文本时要小心。

【讨论】:

  • 感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2017-06-30
  • 1970-01-01
  • 2019-01-11
  • 2018-11-28
  • 1970-01-01
  • 2021-09-05
  • 2019-08-06
相关资源
最近更新 更多