Introduction
In this article, we will learn how to convert java.util.Date to java.sql.Date
Example:
import java.util.Calendar;
import java.util.Date;
public class DateConversion {
public static void main(String[] args) {
Date date = Calendar.getInstance().getTime();
java.sql.Date sqlDate = new java.sql.Date( date.getTime());
}
}
Please note that both these Date classes are outdated now. Use java.Time classes instead of legacy java.util.Date & java.sql.Date with JDBC 4.2 or later.
Comments
Post a Comment