jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes updating date field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "updating date field" Watch "updating date field" New topic

updating date field

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
I have got to update a date field from java.
vSql = "UPDATE R5PERMEVENTS SET PEV_DATE ='" +new java.sql.Date(vCurrentDate.getTime())+"' WHERE PEV_ACTIVE = '+'";
Now the problem is :
new java.sql.Date(vCurrentDate.getTime()) returns values as'2004-07-30
so the query becomes:

Now the oracle doesnot underatand the date format.
How do i change the query in runtime as

Rovas Kram
Ranch Hand

Joined: Aug 08, 2003
Posts: 135
I've used java.text.SimpleDateFormat successfully.

For example,

DateFormat dateFormatter = new SimpleDateFormat(dd-MMM-yyyy HH:mm:ss);
String txt = dateFormatter.format(date);
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

if the database is allways in the same time-zone as the application, you might use 'select sysdate from dual' - the database-date.

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
Thanks for the reply.
I have one query:
Currently in Oracle to enter the date it understands the format dd-MMM-YYYY, can the database setting can change to enter date in different
format depending on th local, say for eg. mm/dd/yy.
In that case will this Datformat of dd-MMM-yyyy will work. Is it universal format will it wotk on every database as i do not wnat to change the format of the date in code.
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

I guess: No.

I had to handle dates to a SqlServer 7.0 database.
I used plain Strings to get the date:
... s = rs.get (3);
and without modifying it, wrote it back:
... query = "INSERT INTO ...." + s + " ....";
It worked well on Jun-12, but not on Jun-13

Times are a real problem on computers, because you have:
- a hardware-generated time
- an os level above, which might use a local time, while the hardware uses GMT.
- a programming languange, which might know of the OS-time, or might not know - using the OS-time or being called with a customized setting
- databases, maybe using global, local, or customized times
- clients, which bring in a third time, with the same possibilities.

of course we may not avoid times.
I agree. Here's the link: http://aspose.com/file-tools
subject: updating date field
It's not a secret anymore!