Hi,

use
  new java.sql.Date(System.currentTimeMillis());
  for SQL Date types or
  new java.sql.Time(System.currentTimeMillis());
  for SQL Time types.

Both extend java.util.Date, so they can be used anywhere a java.util.Date
is accepted.

If you want just to avoid compilation errors when both imported packages
(java.util, java.sql) have a class with the same name - Date
use explicit typing:
   java.util.Date mySimpleDate = new java.util.Date();
or
   java.sql.Date mySqlDate = new
java.sql.Date(System.currentTimeMillis());

Difference betwen java.sql.Date and java.util.Date is that the sql version
cuts off all milliseconds since the begin of the day.

Also in their toString() behaviour.

Cezar.

See following class (SqlDateTest.java):
--------------------------------------------
public class SqlDateTest {
   public static void main(String[] args) {

     long now = System.currentTimeMillis();

     java.sql.Date md = new java.sql.Date(now);

     System.out.println("now is: " + now);

     // Show the milliseconds  stored within md:
     System.out.println("Sql now is: " + md.getTime());

     // there is quite a difference.
     System.out.println("difference in seconds is: " +
         (( now - md.getTime() ) / 1000));

     // See the two dates as string representations:
     System.out.println(" sql.Date is: " + md.toString());
     System.out.println(" util.Date is: " +
            (new java.util.Date(now)).toString());
   }
}
------------------------------------------------------------
On Tue, 13 Jul 1999, Wilson. P wrote:

> Sorry to disturb u again..
>
> That Date() comes under util.* but, since I have included Java.sql.*, It is giving
> compilation error, like no
> constructor matching the Date() .If I include util.*, then agin the problem.
>
> So, I need the same Date() under ..java.sql.*
>
> -wilson
>
> Cezar Totth wrote:
>
> > Hi,
> >
> > simply use:
> >   Date thisMoment = new Date();
> > It is equivalent with:
> >   Date thisMoment = new Date(System.currentTimeMillis())
> >
> > To keep in thisMoment Date variable the moment it was created... ;-)
> >
> > Cezar.
> > On Tue, 13 Jul 1999, Wilson. P wrote:
> >
> > > I'm using 'Prepared statement' only. But, I how to set the default date?..
> > >
> > > wilson
> > >
> > > Chris Pratt wrote:
> > >
> > > > The easiest way is to use a PreparedStatement and the setDate method.
> > > >     (*Chris*)
> > > >
> > > > ----- Original Message -----
> > > > From: Wilson. P <[EMAIL PROTECTED]>
> > > > To: <[EMAIL PROTECTED]>
> > > > Sent: Monday, July 12, 1999 9:00 PM
> > > > Subject: How do I set the current date thru JDBC.
> > > >
> > > > > Hi all
> > > > >
> > > > > I have setTime() function. But, I don't know how to get the current date
> > > > > to set into the Oracle database.
> > > > >
> > > > > bye
> > > > > wilson
> > > > >
> > > > > --
> > > > >
> > > > >
> > > > >
> > > >
> > > > ___________________________________________________________________________
> > > > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > > > of the message "signoff SERVLET-INTEREST".
> > > >
> > > > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > > > Resources: http://java.sun.com/products/servlet/external-resources.html
> > > > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
> > >
> > > --
> > >
> > >
> > >
> >
> > ___________________________________________________________________________
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> > of the message "signoff SERVLET-INTEREST".
> >
> > Archives: http://archives.java.sun.com/archives/servlet-interest.html
> > Resources: http://java.sun.com/products/servlet/external-resources.html
> > LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
> --
>
>
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to