I have the following dml sql (generated by mysql wb):
INSERT INTO `status_need` VALUES (1,1,1,'famille cherchant une autre famille (pour garde partagée ou sortie d\'école)'),(2,1,2,'famille cherchant professionnelle de la garde d\'enfants'),(3,2,1,'professionnelle de la garde d\'enfants cherchant enfants à garder');
When I run it from java, it raises an error probably because of the apostrophe/quote within the value of the field.
I am not sure why that is because the quote is escaped by a backslash and what is more, this SQL was generated by mysql itself.
Can anyone please let me know how to solve this problem?
I’m guessing that your Java code has a string literal that looks like this:
?
The reason that doesn’t work is that in Java, inside a string literal,
\'means'. You need to escape the backslash\by writing\\instead:(Or, as danihp says, you can sidestep the issue by writing
''instead of\': MySQL supports both ways of escaping a single-quote inside a single-quoted string.)