🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.sql › java › sql › Date.html
Date (Java SE 11 & JDK 11 )
January 20, 2026 - A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.sql › java › sql › class-use › Date.html
Uses of Class java.sql.Date (Java SE 11 & JDK 11 )
January 20, 2026 - Report a bug or suggest an enhancement For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
🌐
Java
download.java.net › java › early_access › genzgc › docs › api › java.sql › java › sql › Date.html
Date (Java SE 21 & JDK 21 [build 1])
Creates a LocalDate instance using the year, month and day from this Date object. ... This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.sql › java › sql › Time.html
Time (Java SE 11 & JDK 11 )
January 10, 2025 - This method is deprecated and should not be used because SQL TIME values do not have a date component.
🌐
Oracle
docs.oracle.com › en › java › javase › 11 › docs › api › java.sql › java › sql › Timestamp.html
Timestamp (Java SE 11 & JDK 11 )
January 20, 2026 - A thin wrapper around java.util.Date that allows the JDBC API to identify this as an SQL TIMESTAMP value. It adds the ability to hold the SQL TIMESTAMP fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds.
🌐
GitHub
github.com › openjdk › jdk › blob › master › src › java.sql › share › classes › java › sql › Date.java
jdk/src/java.sql/share/classes/java/sql/Date.java at master · openjdk/jdk
public class Date extends java.util.Date { · /** * Constructs a {@code Date} object initialized with the given · * year, month, and day. * <P> * The result is undefined if a given argument is out of bounds. * * @param year the year minus 1900; must be 0 to 8099. (Note that · * 8099 is 9999 minus 1900.) * @param month 0 to 11 ·
Author   openjdk
🌐
University of Washington
courses.cs.washington.edu › courses › cse341 › 98au › java › jdk1.2beta4 › docs › api › java › sql › Date.html
Class java.sql.Date
To conform with the definition of SQL DATE, the millisecond values wrapped by a java.sql.Date instance must be 'normalized' by setting the hours, minutes, seconds, and milliseconds to zero in the particular time zone with which the instance is associated. See Also: Serialized Form · public Date(int year, int month, int day) Deprecated. Construct a Date · Parameters: year - year-1900 · month - 0 to 11 ·
🌐
GitHub
github.com › pathikrit › better-files › issues › 346
NoClassDefFound: java/sql/Date using JDK 11 · Issue #346 · pathikrit/better-files
September 3, 2019 - I'm getting a NoClassDefFoundError using IntelliJ with JDK 11. I have read that there's some deprecated methods on the sql/Date class, but the class itself is not deprecated, so it should b...
Author   DPachs
🌐
Codedamn
codedamn.com › news › java
How do you convert java.util.Date to java.sql.Date in Java?
July 12, 2024 - If you have an application that needs to work with dates but doesn’t need full compliance with JDBC 3010 standards or other restrictions that apply when working with JDBC 4010. then this method will make it possible for you to do so without having any changes or incompatibilities between your code base and the database itself! ... import java.sql.*; import java.util.*; public class UseJavaSqlTimeStamp { public static void main(String[] args) { java.util.Date newdate = new java.util.Date(); java.sql.Timestamp byusingtimestamp = new java.sql.Timestamp(newdate.getTime()); System.out.println(newdate); System.out.println(byusingtimestamp); } } Code language: Java (java)
Find elsewhere
🌐
Java
download.java.net › java › early_access › loom › docs › api › java.sql › java › sql › Date.html
Date (Java SE 25 & JDK 25 [build 1])
Creates a LocalDate instance using the year, month and day from this Date object. ... This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.
🌐
Oracle
docs.oracle.com › en › java › javase › 25 › docs › api › › java.sql › java › sql › Date.html
Date (Java SE 25 & JDK 25)
January 20, 2026 - Creates a LocalDate instance using the year, month and day from this Date object. ... This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.
🌐
Oracle
docs.oracle.com › javase › 10 › docs › api › java › sql › Date.html
Date (Java SE 10 & JDK 10 )
A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.sql › java › sql › Date.html
Date (Java SE 21 & JDK 21)
January 20, 2026 - Creates a LocalDate instance using the year, month and day from this Date object. ... This method always throws an UnsupportedOperationException and should not be used because SQL Date values do not have a time component.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › sql › Date.html
Date (Java Platform SE 7 )
Constructs a Date object using the given milliseconds time value. If the given milliseconds value contains time information, the driver will set the time components to the time in the default time zone (the time zone of the Java virtual machine running the application) that corresponds to zero GMT.
Top answer
1 of 16
531

Nevermind....

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);

  }

}

explains it. The link is http://www.java2s.com/Tutorial/Java/0040__Data-Type/ConvertfromajavautilDateObjecttoajavasqlDateObject.htm

2 of 16
137

tl;dr

How to convert java.util.Date to java.sql.Date?

Don’t.

Both Date classes are outmoded. Sun, Oracle, and the JCP community gave up on those legacy date-time classes years ago with the unanimous adoption of JSR 310 defining the java.time classes.

  • Use java.time classes instead of legacy java.util.Date & java.sql.Date with JDBC 4.2 or later.
  • Convert to/from java.time if inter-operating with code not yet updated to java.time.
Legacy Modern Conversion
java.util.Date java.time.Instant java.util.Date.toInstant()
java.util.Date.from( Instant )
java.sql.Date java.time.LocalDate java.sql.Date.toLocalDate()
java.sql.Date.valueOf( LocalDate )

Example query with PreparedStatement.

myPreparedStatement.setObject( 
    … ,                                         // Specify the ordinal number of which argument in SQL statement.
    myJavaUtilDate.toInstant()                  // Convert from legacy class `java.util.Date` (a moment in UTC) to a modern `java.time.Instant` (a moment in UTC).
        .atZone( ZoneId.of( "Africa/Tunis" ) )  // Adjust from UTC to a particular time zone, to determine a date. Instantiating a `ZonedDateTime`.
        .toLocalDate()                          // Extract a date-only `java.time.LocalDate` object from the date-time `ZonedDateTime` object.
)

Replacements:

  • Instant instead of java.util.Date
    Both represent a moment in UTC. but now with nanoseconds instead of milliseconds.
  • LocalDate instead of java.sql.Date
    Both represent a date-only value without a time of day and without a time zone.

Details

If you are trying to work with date-only values (no time-of-day, no time zone), use the LocalDate class rather than java.util.Date.

java.time

In Java 8 and later, the troublesome old date-time classes bundled with early versions of Java have been supplanted by the new java.time package. See Oracle Tutorial. Much of the functionality has been back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP.

A SQL data type DATE is meant to be date-only, with no time-of-day and no time zone. Java never had precisely such a class† until java.time.LocalDate in Java 8. Let's create such a value by getting today's date according to a particular time zone (time zone is important in determining a date as a new day dawns earlier in Paris than in Montréal, for example).

LocalDate todayLocalDate = LocalDate.now( ZoneId.of( "America/Montreal" ) );  // Use proper "continent/region" time zone names; never use 3-4 letter codes like "EST" or "IST".

At this point, we may be done. If your JDBC driver complies with JDBC 4.2 spec, you should be able to pass a LocalDate via setObject on a PreparedStatement to store into a SQL DATE field.

myPreparedStatement.setObject( 1 , localDate );

Likewise, use ResultSet::getObject to fetch from a SQL DATE column to a Java LocalDate object. Specifying the class in the second argument makes your code type-safe.

LocalDate localDate = ResultSet.getObject( 1 , LocalDate.class );

In other words, this entire Question is irrelevant under JDBC 4.2 or later.

If your JDBC driver does not perform in this manner, you need to fall back to converting to the java.sql types.

Convert to java.sql.Date

To convert, use new methods added to the old date-time classes. We can call java.sql.Date.valueOf(…) to convert a LocalDate.

java.sql.Date sqlDate = java.sql.Date.valueOf( todayLocalDate );

And going the other direction.

LocalDate localDate = sqlDate.toLocalDate();

Converting from java.util.Date

While you should avoid using the old date-time classes, you may be forced to when working with existing code. If so, you can convert to/from java.time.

Go through the Instant class, which represents a moment on the timeline in UTC. An Instant is similar in idea to a java.util.Date. But note that Instant has a resolution up to nanoseconds while java.util.Date has only milliseconds resolution.

To convert, use new methods added to the old classes. For example, java.util.Date.from( Instant ) and java.util.Date::toInstant.

Instant instant = myUtilDate.toInstant();

To determine a date, we need the context of a time zone. For any given moment, the date varies around the globe by time zone. Apply a ZoneId to get a ZonedDateTime.

ZoneId zoneId = ZoneId.of ( "America/Montreal" );
ZonedDateTime zdt = ZonedDateTime.ofInstant ( instant , zoneId );
LocalDate localDate = zdt.toLocalDate();

† The java.sql.Date class pretends to be date-only without a time-of-day but actually does a time-of-day, adjusted to a midnight time. Confusing? Yes, the old date-time classes are a mess.


About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes. Hibernate 5 & JPA 2.2 support java.time.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, Java SE 10, Java SE 11, and later - Part of the standard Java API with a bundled implementation.
    • Java 9 brought some minor features and fixes.
  • Java SE 6 and Java SE 7
    • Most of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • Later versions of Android (26+) bundle implementations of the java.time classes.
    • For earlier Android (<26), a process known as API desugaring brings a subset of the java.time functionality not originally built into Android.
      • If the desugaring does not offer what you need, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above) to Android. See How to use ThreeTenABP….

The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.