Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

updating date field

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
UPDATE R5PERMEVENTS SET PEV_DATE ='2004-07-30' WHERE PEV_ACTIVE = '+'

Now the oracle doesnot underatand the date format.
How do i change the query in runtime as
UPDATE R5PERMEVENTS SET PEV_DATE ='30-JUL-2004' WHERE PEV_ACTIVE = '+'

Thanks,
Aakash
 
Rovas Kram
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic