You might have noticed the preparedStatement.setDate method of Java JDBC users the older Date object, if you are wondering how to insert the new Java 8+ Date and Time API date objects to the Database using JDBC then you should be using preparedStatement.setObject
Example 1: with LocalDate
Connection connection = DriverManager.getConnection(url,userName,password);
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
preparedStatement.setString(1, null);
preparedStatement.setString(2, "Andrew");
preparedStatement.setObject(3, LocalDate.of(1999, 07, 21));
preparedStatement.setString(4, "Ohio");
int result = preparedStatement.executeUpdate();
mysql> select * from my_uat.students;
+------------+--------------+---------------------+-----------------+
| student_id | student_name | student_dob | student_address |
+------------+--------------+---------------------+-----------------+
| 1 | Mike | 2001-07-22 00:00:00 | New York City |
| 2 | Alex | 2002-08-13 00:00:00 | Chicago |
| 3 | Sam | 2022-01-25 00:00:00 | Ohio |
| 4 | Andy | 2001-10-10 00:00:00 | Japan |
| 5 | Andrew | 1999-07-21 00:00:00 | Ohio |
+------------+--------------+---------------------+-----------------+
Example 2: with LocalDateTime
preparedStatement.setObject(3, LocalDateTime.of(1998, 11, 18,10,20,10));

Have Questions? Post them here!
- Create a Zip file using Java Code programmatically
- Eclipse : A java Runtime Environment (JRE) or Java Development kit (JDK) must be available
- How to Sort a LinkedList in Java
- Loading class com.mysql.jdbc.Driver. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver
- How to declare and initialize Array in Java Programming
- [Fix] java: integer number too large compilation error
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Reading .xls and .xlsx Excel file using Apache POI Java Library
- IntelliJ: Error: Could not find or load main class, java.lang.ClassNotFoundException
- How to get Client IP address using Java Code Example
- Truncate table using Java JDBC Example
- Struts 2 : There is no Action mapped for namespace [/] and action name [form] associated with context path [/proj]
- How to get file path in Idea IntelliJ IDE
- Java Generics explained with simple definition and examples
- Java SE 8 Update 301 available with various bug fixes and security improvements
- Java: Collect Stream as ArrayList or LinkedList
- Java JDBC Connection with PostgreSQL Driver Example
- How to check if Java main thread is alive
- How to fix Java nio NoSuchFileException wile reading a file
- Java 8+ get Day of the Week Examples with LocalDateTime, DateTime, ZonalDateTime and Instant classes
- Ways to Convert Integer or int to Long in Java
- [Java] How to throws Exception using Functional Interface and Lambda code
- [Fix] Spring Boot: mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
- Java: The value of the local variable string is not used
- Java JDBC: Insert Java 8 LocalDate and Time using PreparedStatement
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console - Java
- [Android] Sharing Multiple Images to Twitter App from your App - Twitter
- Parse XML file in Java using DOM Parser - Java
- Java Program to generate random string - Java
- FileZilla Connection time out Failed to retrieve directory listing - FTP
- How to Install Git on Windows - Git
- [fix] bash: ssh: command not found - Bash
- MySQL #6 - Error on delete of './my-database/db.opt' (Errcode: 13 - Permission denied) - MySQL