Date constructor java
The examples you found are for java.util.Date
while you are using java.sql.Date
java.sql.Date
has two constructors
Date(long date)
: Constructs a Date object using the given milliseconds time value.Date(int year, int month, int day)
: which is deprecated
and no default
Date()
constructor.java.util.Date
among others has a default constructor without arguments
Date()
: Allocates a Date object and initializes it so that it represents the time at which it was allocated, measured to the nearest millisecond.
When importing classes, Eclipse will help you fining possible candidates but always check if the first suggestion is really what you want.
You are using the wrong Date
class.
Have a look at your imports. Don't use java.sql.Date
use java.util.Date
instead.
You are importing java.sql.Date
use java.util.Date