Update: Other Answers are now outdated. The modern solution uses the java.time classes defined in JSR 310. These supplanted the terribly flawed legacy date-time classes such as Date, Calendar, and SimpleDateFormat.
Write your SQL using parameters. Use ? as a placeholder for the value to be passed in at runtime.
Use text blocks for easier reading.
Never use the SQL command BETWEEN in date-time work. Spans of time are best defined using the Half-Open approach, where the beginning is inclusive while the ending is exclusive. In contrast, BETWEEN is fully closed, to include both endpoints. For example, a month starts on the first of the month and runs up to, but does not include, the first of the following month.
String sql = """
SELECT id_
FROM event_
WHERE NOT ( date_ < ? )
AND date_ < ?
;
""" ;
You said:
oracle my date format is "dd-mon-yy"
No, incorrect. A DATE column in Oracle database is not text. So it has no “format”.
You said:
systemDate is in format yyyy-mm-dd.
In Java use date-time objects to hold date-time values. Date-time objects are not text, so they have no “format”.
If handed some text as your input date, parse as a java.time.LocalDate object. Your specified format complies with ISO 8601 standard. That standard is used by default in the java.time classes for generating/parsing text. So no need to specify a formatting pattern.
LocalDate start = LocalDate.parse( "2024-01-01" ) ;
LocalDate end = start.plusMonths( 1 ) ; // Cover month of January of 2024.
Pass these objects as the values to be substituted for the ? placeholders in our SQL statement.
myPreparedStatement.setObject( 1 , start ) ;
myPreparedStatement.setObject( 2 , end ) ;