Toblerone Toblerone - 5 months ago 7x
Java Question

JDBC Delete Conditional Statement

Something bugging me that I can't fix and would appreciate some help.

I am trying to from Java delete records where a condition is met. Below is the condition as working in MySQL:

Delete FROM bookingtable WHERE `Date` = '2016-04-23';

Now, trying to implement this into Java I have the below written (which doesn't work):

String s1 = "Delete FROM bookingtable " + "WHERE `Date` = "+formatted;

My Sysout statement which I use for debugging prints out:

Delete FROM bookingtable WHERE `Date` = 2016-04-23

So it looks like I am on the right track except I need that date in apostrophes to make it work? - How do I actually go about that?


You forgot to add escape quotes around formatted:

String s1 = "Delete FROM bookingtable " + "WHERE `Date` = `" + formatted + "`";