What is the JDBC syntax for using a date literal or variable in a standard Statement?
Created May 7, 2012
Joe Sam Shirah While you are generally advised to use a PreparedStatement and let the driver handle the syntax, the following is the standard form for regular Statements.
The general escape syntax for standard SQL date columns is:
{d 'yyyy-mm-dd'}
For literals:
String sSQL =
"SELECT colName FROM aTable " +
"WHERE colDate = {d '2001-10-21'}"
For variables ( note that toString() is implicitly called on the date variable ):
java.sql.Date jsqlDate;
... // set date
String sSQL =
"SELECT colName FROM aTable " +
"WHERE colDate = {d '" + jsqlDate + "'}"