Avoid legacy classes
Never use either Date
class. Both are part of the terrible date-time legacy classes that were years ago supplanted by the modern java.time classes defined in JSR 310.
LocalDate
For a date-only value, use LocalDate
class.
Your input string complies with the “basic” variation of the ISO 8601 standard format, YYYYMMDD. So use the predefined formatter, DateTimeFormatter.BASIC_ISO_DATE
.
String input = "19990715" ;
LocalDate birthDate = LocalDate.parse( input , DateTimeFormatter.BASIC_ISO_DATE ) ;
Write your SQL like the following.
Tip: Use trailing underscore in all your database naming to avoid collision with reserved keywords. The SQL standard promises explicitly to never use a trailing underscore. See this Answer by me.
Another tip: Use text blocks for your embedded SQL code.
String sql =
"""
INSERT INTO member_ ( id_ , birth_date_ )
VALUES ( ? , ? )
;
""";
Exchange the LocalDate
object for writing to database.
myPreparedStatement.setObject( 2 , birthDate ) ;
When retrieving the data value from the database.
LocalDate birthDate = myResultSet.getObject( … , LocalDate.class ) ;
All this has been covered many times on Stack Overflow. Search to learn more. You will find complete source code for example apps that create a table, insert rows, and retrieve rows.