• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

date insert autometically in to DB at the time of submitting form

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

can someone please help me.my problem is i have no column on the user interface and when i submitt this form the Date is autometically insert into database this Date must be server Date not the client Date bcz client Date may be wrong but server date always right please give an example of code in JAVA that would some how solve my problem.

please help me as soon as possible!!!

thank you!!!
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sarika,

U can do the same. Are u calling a servlet/jsp when the form is submitted
in both cases u could call Calendar.getInstance().getTime() which gives u the server date and the same can be used in the insert statement of ur table
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks but can u give some example of code about that.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What database are you using?
 
sarika Gupta
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, satish

i m using SQL Server as a Database.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I asked because mysql has a timestamp datatype that automatically updates itself when the row is updated.

With SQL-Server, you could write a trigger that does this automatically at the database level, if you so desired.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to JDBC
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want the db to do the date, just call the function that your DB uses to get the current date in your update call ( function for MSSQL is getDate() ):


an update would work the same:

[ April 29, 2005: Message edited by: Jamie Robertson ]
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ben Souther:
I asked because mysql has a timestamp datatype that automatically updates itself when the row is updated.



As I haven't worked with mySQL.
Is there any column, of Timestamp datatype, in every table of mySQL? Like we have ROWID in Oracle.
[ April 30, 2005: Message edited by: Adeel Ansari ]
 
Ranch Hand
Posts: 1087
Oracle Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
since poster of this thread is using sql server,which already has Datetime datatype for dates and can be used as setTimeStamp() of PreparedStatement or sql server has GETDATE()function to get date in sql


Shailesh
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd use GETDATE() in the sql, or in oracle SYSDATE (I think mysql uses 'now()')

I wouldn't use a db trigger to insert the date, here's why.

With our current prod db we did use a trigger to update the date to now on insert.

However, we've also had to do a lot of data insertion of old data, and to insert this data and keep the original dates in the old data, you have to turn off the trigger before running the import/insert.

This means a production downtime (because turning off the trigger during normal operation would be bad of course).

In hindsight, we would have stuck with a 'not null' constraint on the date time column and gone with 'sysdate' or the like in the sql.
 
You can't have everything. Where would you put it?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic