Home  >  Q&A  >  body text

How to solve this SQL syntax error problem?

I encountered an error with the server regarding a request to the database.

This is the error message:

java.sql.SQLSyntaxErrorException: There is an error in your SQL syntax; check the manual for your MySQL server version for ', Regione='e', provincia='q', comune= on line 1 Correct syntax to use around 'w''

This is the SQL query in question:

PreparedStatement ps = con.prepareStatement("SELECT * FROM azienda WHERE id_categoria=?, 
regione=?, provincia=?, comune=?");
        ps.setInt(1, id);
        ps.setString(2, regione);
        ps.setString(3, provincia);
        ps.setString(4, comune);

Thanks in advance!

P粉409742142P粉409742142384 days ago422

reply all(1)I'll reply

  • P粉135799949

    P粉1357999492023-09-07 14:55:18

    If you use multiple conditions, try using AND:

    SELECT * 
    FROM azienda 
    WHERE id_categoria=? 
    AND regione=? 
    AND provincia=? 
    AND comune=?

    reply
    0
  • Cancelreply