Input is being processed using the java.util.Date
class. You want to use this data to create an SQL query. Therefore, you must convert to an object in the java.sql.Date
class.
However, we found that the java.util.Date object cannot be automatically/forced to an object of class java.sql.Date.
The Java API itself is still unfamiliar to me. I don't know how to handle this.
sql datetime java date
Don't worry.
You can do it as follows.
public class MainClass {
public static void main(String[] args) {
java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println("utilDate:" + utilDate);
System.out.println("sqlDate:" + sqlDate);
}
}
Please refer to the following link.
© 2024 OneMinuteCode. All rights reserved.