Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why two date classes one in java.util.Date and java.sql.Date?

Tags:

java

HI I like to know why there are two Date classes in two different packages one in java.util.Date and one in java.sql.Date? Whats the use of having two Date classes?

like image 890
giri Avatar asked Jan 20 '10 19:01

giri


People also ask

What is the difference between Java Util date and Java sql date?

sql. Date just represent DATE without time information while java. util. Date represents both Date and Time information.

How is date stored in database * 1 point Java sql date Java Util date Java sql datetime Java Util datetime?

In fact, the date is stored as milliseconds since the 1st of January 1970 00:00:00 GMT and the time part is normalized, i.e. set to zero. Basically, it's a wrapper around java. util. Date that handles SQL specific requirements.

Does Java sql contain date class?

The java. sql. Date class represents the only date in Java. It inherits the java.

How does Java compare dates in sql?

In Java, two dates can be compared using the compareTo() method of Comparable interface. This method returns '0' if both the dates are equal, it returns a value "greater than 0" if date1 is after date2 and it returns a value "less than 0" if date1 is before date2.

Is Java sql date deprecated?

Deprecated. This method is deprecated and should not be used because SQL Date values do not have a time component. Parameters: i - the hour value.

What is difference between Java date and calendar classes?

What is difference between Java Date and Calendar classes? The difference between Date and Calendar is that Date class operates with specific instant in time and Calendar operates with difference between two dates.


2 Answers

java.util.Date is Java's Date data type.

java.sql.Date is a JDBC wrapper for SQL dates.

The two are represented completely differently internally.

.NET has the same concepts (but a better naming convention to differentiate the two in my opinion) with System.DataTime and System.Data.SqlTypes.SqlDateTime

like image 162
Justin Niessner Avatar answered Sep 22 '22 05:09

Justin Niessner


java.sql.Date

A thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. A milliseconds value represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT.

like image 36
Crozin Avatar answered Sep 21 '22 05:09

Crozin