MarwenBta MarwenBta - 3 months ago 10
MySQL Question

how to solve SQL syntax error?

try {
String req = "INSERT INTO nouvelle_installation" +
"values('" + ref + "','" + today + "','" + check + "','" + nbligne +
"','" + tligne + "','" + categorie + "','" + instal + "','" + cin +
"','" + user + "','" + prenom+"','" + numC + "','" + num + "','" + voie +
"','" + tvoie + "','" + imm + "','" + app + "','" + etage +
"','" + codep + "')";

Statement m = s.getCon().createStatement();
m.executeUpdate(req);
} catch (SQLException e1) {
e1.printStackTrace();
}



com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Erreur de syntaxe près
de ''aaa','2012-04-10',' ','------','---------------','-------',
'Nouvelle Installati' à la ligne 1

Answer

use prepared statements instead of concatenating your statement.

Also prepared statements is faster than Statement.

You are missing a space between your table-name and the keyword values.