Difference between java.sql.Date and java.util.Date

Showing Answers 1 - 25 of 25 Answers

shashi Ranjan Kumar

  • Mar 25th, 2006
 

The d/w java.util.date and java.sql is miner diffrence. The java.util.date is return the date with time and date and sql.date is return data with is retrive the data entry date i.e whitch time the data has enry or not.

suresh

  • Mar 27th, 2006
 

hi Rajan,how r u ? your answer for the difference between java.util.Date & java.sql.Date is not understandable.so please give more information about that.thanking you suresh.

  Was this answer useful?  Yes

Kumaravel

  • Apr 1st, 2006
 

java.sql.Date stores only date information, not times. Simply converting a java.util.Date into a java.sql.Date will silently set the time to midnight.

  Was this answer useful?  Yes

harshgupta

  • Apr 7th, 2006
 

Hi

1) java.util.Date is the superclass for java.sql.Date i.e public class Date extends java.util.Date { }

2) java.sql.Date is used for databases where we just need to store date and not time but java.util.date returns Date as well as time

3) java.util.Date has constructor with 0 parameters but java.sql.Date does not has the one, so we canot use new Date() here, time in milliseconds needs to be passed

Regards

(Harsh Gupta)

  Was this answer useful?  Yes

dillip kundu

  • Apr 13th, 2006
 

Hi,friends,the answer is not clear enough.please send the correct data and maintain the uniquenees.if u don't know please don't answer.thanks!!

  Was this answer useful?  Yes

shelvammsc@yahoo.co.in

  • May 17th, 2006
 

Hi java.util.Date contains many methods.This class extends java.lang.object implements java.io.Serializable,java.lang.Cloneable, java.lang.Comparableit can contains both bean properties are also availablewhere as the java.sql.Date-------------- java.sql.Date extends java.util.Date {

  Was this answer useful?  Yes

Srinivas

  • May 21st, 2006
 

Hi Friends,

This is the main difference

java.util.date ---------->dd mm yyyy   hh:mm:ss

java.sql.date----------->dd mm yyyy    hh:mm:ss: ms

ok bye..........

Keeps Smiling And Mailing

srinadh

  • Nov 30th, 2006
 

Hi,

This was exact output about java.util.Date and java.sql.Date:

  java.util.Date date1 = new java.util.Date();
  System.out.println("Hello World! "+ date1);
  
  java.sql.Date date2 = new java.sql.Date(date1.getTime());
  System.out.println("Hello World! "+ date2);

java.util.Date ----> here date1 object prints date and time.

java.sql.Date ----> here date2 object prints only date (2006-11-30)

Thanks,

Srinadh

  Was this answer useful?  Yes

1. The java.sql.Date stores only day, month and year.
2. The java.util.Date stores day, month, year along with time information upto milliseconds accuracy.

the sql versions are namely:
1. java.sql.Date - having only date information
2. java.sql.Time - having only time information
3. java.sql.TimeStamp - having date + time information with nanoseconds precision.

These are created as a wrapper for SQL DATE, TIME, TIMESTAMP datatypes which the java.util.Date is inefficient to handle.

dileep Mishra

  • Aug 24th, 2011
 

java.sql.date is not a date time, means it does not stored time, only it stores date.

But java.util.Data store long, date and time both.

NarendraKumar

  • Mar 6th, 2012
 

Explanation:
public class ((java.util.Date extends java.lang.Object)) implements java.io.Serializ
able,java.lang.Cloneable,java.lang.Comparable



java.sql.Date extends the java.uti.Date cls obj
so java.sql.Date is the subclass of java.util.Date



mainly java.sql.Date are used for jdbc application to insert date value into dbtable......Date value cannot insert
directly............follow some steps



1)end user reads the date in string format

2)after reads the date it convert into util.Date cls obj

3)after completion of 2nd step again util.Date cls obj convert into java.sql.Date cls obj........it is the way to print the date in the dbtable as column................

to better understand see the following code..............................

Code
  1. import java.sql.*;

  2. import java.util.*;

  3. import java.text.*;

  4. class DateDemo3

  5. {

  6.         public static void main(String[] args)  throws Exception

  7.         {

  8.                

  9.        

  10.                 Scanner sc=new Scanner(System.in);

  11.                 System.out.println("enter the dob");

  12.                 String dob=sc.next();

  13.                 SimpleDateFormat sdf=new SimpleDateFormat("MM-dd-yy");

  14.         java.util.Date ud=sdf.parse(dob);

  15.                 long msdob=ud.getTime();//according to the echo standrard since jan 1970 it counts to till date and gives the difference

  16.  

  17.         java.sql.Date sqdob=new java.sql.Date(msdob);

  18.                 System.out.println(sqdob);

  19.  

  20.  

  21.        

  22.         }

  23. }

  24.  

dineshxp

  • Mar 19th, 2012
 

java.util.date is used to show date and time of the system

java.sql.date is used to show the date of retrieved data from database and also it shows entered date to database

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions