The below code doesn't seem to insert a row into the table 'students' as I'd like it to.
The SQLException getMessage() method returns the following:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, Last Name, School ID Number) VALUES('Joel', 'Christophel', '101059')' at line 1
Did you really give your columns names which have spaces in them, like "First Name"? If so, then you're going to have to escape them to make the SQL which contains them into valid SQL.
I think that might require putting quotes around them, but I don't see anything about that in the MySQL documentation except for something which says that you escape reserved words by putting a back-tick before them.
Escaping quotation marks around the column names didn't work, so I just removed the spaces from the column names, which allowed me to insert the row. Thanks for your help!
(In my opinion, using standard column names -- no spaces -- is preferable to having to escape them with back-ticks every time you use them in a query.)
(In my opinion, using standard column names -- no spaces -- is preferable to having to escape them with back-ticks every time you use them in a query.)
I seriously dislike have spaces in column names, but they all seem to allow it these days.
Paul Clapham wrote:(In my opinion, using standard column names -- no spaces -- is preferable to having to escape them with back-ticks every time you use them in a query.)
+1 for that. Putting spaces in your table/column names, or making them case-sensitive, just gives you another potential source of errors further down the line.
ex-Oracle bloke
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.