문제

I'm trying to delete a contact from an address book that uses a MySQL database and I thought this would be how it was done, however an exception is thrown and it prints "Unknown column 'john' in 'where clause'". Each contact has 5 attributes - name, mobile, homephone, email and address and one of the contacts name is 'john'.

public static void deleteContact(String name)
{
     Connection con = connect();// function that returns mySQL function
     Statement s = con.createStatement();
     try{
         s.executeUpdate("Delete from contactDetails where name =" + name);
     }
     catch(SQLException e){
         System.out.println(e.getMessage());
     }
}
도움이 되었습니까?

해결책

Surround your variable value with quotes.

"... where name ='" + name + "'");
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top