0

I'm trying to execute some data in a table. The issue is that I have to insert the name O'Donnel into a field named name and I'm getting a format error.

insert into Person (name) values ('O'Donnel');

I also don't want to use double floating commas ("") because I'm inserting this data using a JDBC system and Strings in Java already use those.

So... is there any other solution?

user157629
  • 624
  • 4
  • 17
  • 3
    `insert into Person (name) values ('O''Donnel');`, i.e. double the quote inside a string literal. – jarlh Mar 26 '20 at 10:24
  • 1
    .. or standard escaping with backslash - `insert into Person (name) values ('O\'Donnel')`. See [String Literals](https://dev.mysql.com/doc/refman/8.0/en/string-literals.html). – Akina Mar 26 '20 at 10:27
  • Doubled single quote is according to the ANSI/ISO SQL standard. – jarlh Mar 26 '20 at 11:43

1 Answers1

-2

Try This

INSERT INTO Person(name) VALUES ("O'Donnel");
T.Maharani
  • 108
  • 5
  • I guess that would work, but as I said in the answer, I was looking an alternative to this. This worked for me: `INSERT INTO PERSON (name) VALUES ('O''Donnel');` as @jarlh said. – user157629 Mar 26 '20 at 15:22