I’ve been using PreparedStatements throughout my entire database where you can use setDate(index, data), however would it work to use a Date object like this?
"SELECT * FROM table WHERE date BETWEEN " + date + " AND " + otherDate
Are there any online tools that I can use to test this?
I do not believe this function will work:
Since your trying to concatenate two
Dateobjects with severalStringliterals. You would need to use aDateFormatterto turn theDateinto aString.You should stick with the
PreparedStatements and avoid creating SQL statements by concatenating Strings/Values. ThePreparedStatementis going to offer you some protection againstsql injection, while the String concatenation method is going to expose you to the risk of sql injection.