The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to Convert java.util.Date to java.sql.Date - Example

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 1090
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to Convert java.util.Date to java.sql.Date - Example Posted: Feb 6, 2014 8:50 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to Convert java.util.Date to java.sql.Date - Example
Feed Title: Java67
Feed URL: http://www.java67.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
There are two date classes in Java, one in java.util package and other in java.sql package. Though both are known as Date class, their are some difference between java.util.Date and java.sql.Date e.g. Former is used whenever a Date is required in Java application, while later is used to read and store DATE SQL type from database. There is one more important difference is, java.util.Date stores both date and time values, while java.sql.date only stores date information, without any time part. As per javadoc, java.sql.date is a thin wrapper around a millisecond value that allows JDBC to identify this as an SQL DATE value. 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 SQL date vs Util date for few more differences. In this Java tutorial, we will learn how to convert a java.util.Date to java.sql.Date, as we often need to do this when storing values into database. Since java.util.Date is standard way to represent date and time in Java, I only keep java.sql.Date up-to JDBC or DAO Layer, by the way if you need date with time, then use SQL TIMESTAMP type instead of DATE. It's also notable that java.sql.Date is subclass of java.util.Date, but it doesn't mean you can pass around this in place of java.util.Date, because it violates Liskov Substitution principle. All time related methods of java.sql.Date throws IllegalArgumentException, as shown below
Read more ยป

Read: How to Convert java.util.Date to java.sql.Date - Example

Topic: Does your pay measure up? The 2014 tech salary guide Previous Topic   Next Topic Topic: Looking for your aaS? (IaaS vs. PaaS vs. SaaS vs. BaaS)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use