aspose file tools*
The moose likes JDBC and the fly likes On java.sql.Timestamp and java.sql.Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "On java.sql.Timestamp and java.sql.Date" Watch "On java.sql.Timestamp and java.sql.Date" New topic
Author

On java.sql.Timestamp and java.sql.Date

Bhuvana Bala
Greenhorn

Joined: Jul 19, 2001
Posts: 10
hi all,
Can anybody help me to convert to convert 12-JAN-2000 to timestamp.
Also:
If I declare the date variable as java.sql.Date with the above input I am not able to get the timestamp format
I have declare date as Datetime in SQL SERVER.
In java should I declare as java.sql.Date OR java.sql.Timestamp?
In either way pl. help me with the code.
thanx a lot.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Use getTime() method of java.sql.Date to instantiate java.sql.Timestamp(long time).
Bhuvana Bala
Greenhorn

Joined: Jul 19, 2001
Posts: 10
Originally posted by dip ch:
Use getTime() method of java.sql.Date to instantiate java.sql.Timestamp(long time).


Can u please be clear. I tried with it .But I dont get it.
Now I need to convert calendar. to Timestamp.
Calendar c1= Calendar.getInstance();
c1.set(2000,12,32);
java.util.Date d= c1.getDate();
java.sql.Date dt=new java.sql.Date(d.getTime);
Now dt is the sql Date. I need java.sql.Timestamp format.Pl. help
pl. see
Thanx

[This message has been edited by Bhuvana Bala (edited July 24, 2001).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
you need to read java api documentation. java school of this site is also a good place.
corrected code:
java.util.Calendar c1= java.util.Calendar.getInstance();
c1.set(2000,12,32);
java.util.Date d= c1.getTime();
java.sql.Date dt=new java.sql.Date(d.getTime());
(Sorry for late reply - naming convention of the site created problem!!)
bye
DC
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: On java.sql.Timestamp and java.sql.Date