Java 您的SQL语法有错误;查看与MySQL服务器对应的手册

Java 您的SQL语法有错误;查看与MySQL服务器对应的手册,java,mysql,sql,tomcat,syntax,Java,Mysql,Sql,Tomcat,Syntax,我在tomcat上运行java文件时遇到了问题。我假设能够编辑我放在数据库中的记录,当我编辑记录时,它们什么也不做。当我试图编辑记录时,Tomcat抛出了这个错误 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您有一个 SQL语法错误;检查与您的产品相对应的手册 MySQL服务器版本,以便在“WHERE cus_id”附近使用正确的语法= 第1行的“13” 我认为这是有错误的代码,因为它有所有的SQL命令。删除功能起作用。我就

我在tomcat上运行java文件时遇到了问题。我假设能够编辑我放在数据库中的记录,当我编辑记录时,它们什么也不做。当我试图编辑记录时,Tomcat抛出了这个错误

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:您有一个 SQL语法错误;检查与您的产品相对应的手册 MySQL服务器版本,以便在“WHERE cus_id”附近使用正确的语法= 第1行的“13”

我认为这是有错误的代码,因为它有所有的SQL命令。删除功能起作用。我就是不能编辑记录

谢谢你的帮助

package crud.data;

import java.sql.*;
import java.util.ArrayList;

import crud.business.Customer;

public class CustomerDB
{
 //insert method (pass customer object to parameter customer)
 public static int insert(Customer customer)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
//comment
String query
  = "INSERT INTO customer (cus_fname, cus_lname, cus_street, cus_city, 
   cus_state, cus_zip, cus_phone, cus_email, cus_balance, cus_total_sales, 
   cus_notes) "
    + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
try {
  ps = connection.prepareStatement(query);
  ps.setString(1, customer.getFname());
  ps.setString(2, customer.getLname());
  ps.setString(3, customer.getStreet());
  ps.setString(4, customer.getCity());
  ps.setString(5, customer.getState());
  ps.setString(6, customer.getZip());
  ps.setString(7, customer.getPhone());
  ps.setString(8, customer.getEmail());
  ps.setString(9, customer.getBalance());
  ps.setString(10, customer.getTotalSales());
  ps.setString(11, customer.getNotes());

  return ps.executeUpdate();
} catch (SQLException e){
  System.out.println(e);
  return 0;
} finally {
  DBUtil.closePreparedStatement(ps);
  pool.freeConnection(connection);
    }
  }

 //update method
 public static int update(Customer customer)
 {
  ConnectionPool pool = ConnectionPool.getInstance();
  Connection connection = pool.getConnection();
  PreparedStatement ps = null;

String query = "UPDATE customer SET "
    + "cus_fname = ?, "
    + "cus_lname = ?, "
    + "cus_street = ?, "
    + "cus_city = ?, "
    + "cus_state = ?, "
    + "cus_zip = ?, "
    + "cus_phone = ?, "
    + "cus_email = ?, "
    + "cus_balance = ?, "
    + "cus_total_sales = ?, "
    + "cus_notes = ?, "
    + "WHERE cus_id = ?";
try {
  ps = connection.prepareStatement(query);
  ps.setString(1, customer.getFname());
  ps.setString(2, customer.getLname());
  ps.setString(3, customer.getStreet());
  ps.setString(4, customer.getCity());
  ps.setString(5, customer.getState());
  ps.setString(6, customer.getZip());
  ps.setString(7, customer.getPhone());
  ps.setString(8, customer.getEmail());
  ps.setString(9, customer.getBalance());
  ps.setString(10, customer.getTotalSales());
  ps.setString(11, customer.getNotes());
  ps.setString(12, customer.getId());

  return ps.executeUpdate();
} catch (SQLException e) {
  System.out.println(e);
  return 0;
} finally {
  DBUtil.closePreparedStatement(ps);
  pool.freeConnection(connection);
     }
   }
}

最后一个值上有一个逗号

+ "cus_notes = ?, "
所以用

+ "cus_notes = ? "

第64行:删除
+“cus_notes=?,”

中的逗号。您应该发布更多的错误,更容易识别错误的位置,现在根据提示是SQL语法错误。

这是语法错误,如控制台日志中所示

最后一个值的末尾有逗号,请将其删除,然后再试一次


“cus\u notes=?”

在更新查询中键入的代码太多:
+“cus\u notes=?,”
(在
前面加上逗号,其中
)。