4

I am trying to create a maximum date in my program with the following:

import java.util.Date;
import java.sql.Timestamp;

Date maxDate = new Date(Long.MAX_VALUE);
...
Timestamp ts = new Timestamp(maxDate.getTime());

If I am correct maxDate.getTime(); returns with the value of Long.MAX_VALUE so it doesn't really matter, I could have written simply new Timestamp(Long.MAX_VALUE); Am I right?

My problem is that my program gives the following exception at this point:

java.sql.SQLException: Year out of range.

So what is the maximum long value that can be passed to Timestamp? Or is there anything else I am missing here?

I am using an Oracle database if it matters.

Thanks in advance!

Tamas G.
  • 677
  • 3
  • 21
  • 38

1 Answers1

6

The maximum year java.util.Date can handle is year 292278994

When will the java date collapse?

while the maximum year value for java.sql.Timestamp is 9999

Pretty sure thats how it works due to this error i kept getting:

ORA-01841: (full) year must be between -4713 and +9999, and not be 0

buræquete
  • 14,226
  • 4
  • 44
  • 89
cristianhh
  • 128
  • 12
  • I found [IBM knowledge center, which said the same thing too](https://www.ibm.com/support/knowledgecenter/el/SSEPGG_9.7.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0053436.html). – AechoLiu Jul 02 '18 at 07:31