GeekInterview.com
Series: Subject: Topic:
Question: 103 of 124

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

Asked by: Interview Candidate | Asked on: Mar 24th, 2006
Showing Answers 1 - 13 of 13 Answers
shashi Ranjan Kumar

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
suresh

Answered On : 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.

  
Login to rate this answer.
Kumaravel

Answered On : 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.

  
Login to rate this answer.
harshgupta

Answered On : Apr 7th, 2006

View all answers by harshgupta

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)

  
Login to rate this answer.
dillip kundu

Answered On : 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!!

  
Login to rate this answer.
shelvammsc@yahoo.co.in

Answered On : 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 {

  
Login to rate this answer.
Srinivas

Answered On : 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

  
Login to rate this answer.
srinadh

Answered On : 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

  
Login to rate this answer.
pravinsharma

Answered On : Jul 6th, 2009

View all answers by pravinsharma

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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
vinodkashyap

Answered On : Jul 9th, 2009

View all answers by vinodkashyap

java.sql.Date - Used mainly while storing in the database

java.util.Date - Used to format the date

  
Login to rate this answer.
dileep Mishra

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.
NarendraKumar

Answered On : 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.  

Yes  1 User has rated as useful.
  
Login to rate this answer.
dineshxp

Answered On : Mar 19th, 2012

View all answers by dineshxp

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

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Question Categories

Core Java Interview Questions

EJB Interview Questions

Hibernate Interview Questions

Java Interview Questions

Java Patterns Interview Questions

JDBC Interview Questions

JMS Interview Questions

JSP Interview Questions

Java OOPS Interview Questions

Ruby Interview Questions

Servlets Interview Questions

Spring Interview Questions

Struts Interview Questions

Websphere Interview Questions

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.