Difference betwixt java.sql.Time, java.sql.Timestamp as well as java.sql.Date is most mutual JDBC inquiry appearing on many core Java interviews. As JDBC provides iii classes java.sql.Date, java.sql.Time as well as java.sql.Timestamp to stand upward for appointment as well as fourth dimension as well as you lot already convey java.util.Date which tin post away stand upward for both appointment as well as time, this inquiry poses lot of confusion amidst Java programmer as well as that’s why this is 1 of those tricky Java questions which is tough to answer. It becomes actually tough if differences betwixt them is non understood correctly. We convey already seen unopen to oftentimes asked or mutual JDBC questions similar why JDBC has java.sql.Date despite java.util.Date as well as Why usage PreparedStatement inwards Java in our concluding tutorials as well as nosotros volition come across departure betwixt java.sql.Date, java.sql.Time as well as java.sql.Timestamp inwards this article. By the means apart from these JDBC interview questions, if you lot are looking to larn most from JDBC you lot tin post away also come across 4 JDBC surgical physical care for tips as well as 10 JDBC best practices to follow. Those article non entirely aid you lot to empathise as well as usage JDBC improve just also aid on interviews. Let’s come upward dorsum to departure sql time, timestamp as well as sql date.
Difference betwixt java.sql.Time, java.sql.Timestamp as well as java.sql.Date:
JDBC inwards Java has iii date/time types corresponding to DATE, TIME as well as TIMESTAMP type of ANSI SQL. These types are used to convert SQL types into Java types.
1) First departure on java.sql.Time vs java.sql.Timestamp vs java.sql.Date is virtually information they stand upward for :
JDBC TIME or java.sql.Time stand upward for entirely fourth dimension information e.g. hours, minutes as well as seconds without whatever appointment information.
JDBC DATE or java.sql.Date stand upward for entirely appointment information e.g. year, month as well as day without whatever fourth dimension information.
JDBC TIMESTAMP or java.sql.Timestamp represent both appointment as well as fourth dimension information including nanosecond details.
2) java.sql.Time as well as java.sql.Timestamp extends java.util.Date aeroplane just java.sql.Date is independent.
3) Time information from java.sql.Date as well as Date information from java.sql.Time is normalized as well as may laid to cypher inwards guild to confirm ANSI SQL DATE as well as TIME types.
So departure betwixt Time, Timestamp as well as Date of SQL packet is clear inwards damage of what they represent. On opposite java.util.Date also stand upward for Date as well as fourth dimension information just without nanosecond details as well as that's why many people prefer to shop appointment equally long value (millisecond passed from epoch Jan 1, 1970 00:00:00.000 GMT). If you lot compare to java.sql.Timestamp amongst equals() method it volition render false equally value of nanosecond is unknown.
That's all on departure betwixt java.sql.Date, java.sql.Time as well as java.sql.Timestamp. All differences lies on what just the represent. This kinds of questions are worth looking earlier going to whatever JDBC interview equally fourth dimension as well as appointment are integral usage of whatever JDBC interview.
Further Learning
JSP, Servlets as well as JDBC for Beginners: Build a Database App
Complete JDBC Programming Part 1 as well as 2
How to connect Oracle database from Java program